﻿Imports System
Imports System.IO
Imports System.Text
Imports System.Collections.Generic
Module modMain
    Public Structure AC_Supply
        Public Coop As String
        Public DF As String
        Public Supply As Integer
    End Structure
    Public Structure AC_Type
        Public Type As Integer
        Public Weapons As String
        Public DF As String
        Public Coop As String
        Public Max As Integer
        Public Min As Integer
        Public Side As Integer
        Public Resupply As Integer
        Public Country As String
    End Structure
    Public Structure Squad_Type
        Public Loc As String
        Public iLoc As Integer
        Public Coop As String
        Public DF As String
        Public Number As Integer
        Public Suppressed As Integer
        Public FuelLimit As Integer
        Public Type As Integer
        Public Side As Integer
        Public Squad As String
        Public Weapon As String
        Public Max As Integer
        Public Min As Integer
        Public WeaponsDF As String
        Public Country As String
    End Structure
    Public Structure SC_Aircraft 'INI Aircraft Types
        Public Type As String
        Public Count As Integer
        Public Weapons As String
        Public Side As Integer
    End Structure
    Public Structure Carry 'What is carried on what
        Public Main As String
        Public Secondary As String
    End Structure
    Public Structure Weather
        Public Velocity As Integer
        Public Direction As Integer
        Public Top As Integer
        Public Turbulence As Integer
        Public Gust As Integer
    End Structure
    Public Structure Weap
        Public AC As String
        Public Weapon As String
    End Structure
    Public Structure Plt
        Public Name As String
        Public ID As String
        Public Coop As String
        Public Base As String 'Location
        Public BaseLanded As String ' Location
        Public iBase As Integer 'Location Number
        Public iBaseLanded As Integer 'Location Number
        Public iBP As Integer 'Bornplace Number
        Public Squad As Integer 'Squad Name as String
        Public iSquad As Integer 'Squad as Integer
        Public Status As Integer
        Public PltStatus As String 'cockpit, bailed, captured, dead
        Public ACStatus As String 'inflight, crashed, shotdown, ditched, landed
        Public Fact As Integer 'Factory Tgts destroyed
        Public Grnd As Integer 'Ground Tgts Destroyed
        Public Tank As Integer 'Tanks destroyed
        Public AC As Integer 'Parked AC destroyed
        Public Ship As Integer
        Public Train As Integer
        Public Kills As Integer 'Kills
        Public Side As Integer
        Public Gun As Integer
        Public Time As Date
        Public InFlight As Integer
        Public FriendAC As Integer
        Public FriendGnd As Integer
        Public SupplyMis As Integer
        Public FerryMis As Integer
        Public Infantry As Integer
        Public Plate As Integer
        Public Bridge As Integer
    End Structure
    
    Public Structure Stationary 'Stationary Objects
        Public Ident As String
        Public Active As Boolean
        Public Unit As String
        Public Side As Integer
        Public X As Double
        Public Y As Double
        Public Head As Double
        Public Other As String
        Public Loc As String
        Public intLoc As Integer
    End Structure
    Public Structure RocketType 'Rocket Objects
        Public Ident As String
        Public Active As Boolean
        Public Unit As String
        Public Side As Integer
        Public X As Double
        Public Y As Double
        Public Head As Double
        Public Time As Single
        Public Num As Integer
        Public Interval As Single
        Public Xtgt As Double
        Public Ytgt As Double
        Public Loc As String
        Public intLoc As Integer
        Public Size As Integer
        Public Curr As Integer
        Public Columns As Integer
        Public Fuel As Integer
        Public Supply As Integer
        Public Troops As Integer
        Public Artillery As Integer
        Public Amp As Integer
        Public BR As Integer
        Public ConType As Integer
    End Structure

    Public Structure Building
        Public Unit As String
        Public Size As Integer
        Public Fuel As Integer
        Public Supply As Integer
        Public Troops As Integer
        Public Cols As Integer
        Public Alive As String
        Public Dead As String
        Public Repair As Integer
        Public Manufacture As Single
    End Structure
    Public Structure Column
        Public Ident As String
        Public Unit As String
        Public Side As Integer
        Public sFrom As String
        Public iFrom As Integer
        Public sTo As String
        Public iTo As Integer
        Public Orig As String
        Public OrigSize As Integer          'Original Size of Column
        Public ROF As String
        Public Size As Integer
        Public Curr As Integer              'Current Size of Column?
        Public Columns As Integer
        Public Fuel As Integer
        Public Supply As Integer
        Public Troops As Integer
        Public Type As Integer
        Public Direction As Integer
        Public ConType As Integer           'Convoy Type?
        Public Artillery As Integer
        Public Armor As Integer
        Public Amp As Integer
        Public BR As Integer
        Public Carrier As Integer
        Public Unload As Integer
        Public Hold As Boolean
        Public MultUnit As Integer
        Public AllowLoad As Integer
    End Structure
    Public Structure Location
        Public Loc As String
        Public Road As String
        Public intRoad As Integer
        Public Side As Integer
        Public X As Double
        Public Y As Double
        Public MaxTroops As Integer
        Public Allied As Integer
        Public Axis As Integer
        Public Type As Integer
        Public MaxSup As Integer
        Public Supply As Integer
        Public MaxFuel As Integer
        Public Fuel As Integer
        Public AxisX As Double
        Public AxisY As Double
        Public AxisH As Integer
        Public AlliedX As Double
        Public AlliedY As Double
        Public AlliedH As Integer
        Public Suppressed As Integer
        Public FuelLimit As Integer 'Fuel limit at this location
        Public Points As Integer
        Public Moving As Boolean
        Public ParaDrop As Integer
        Public Infantry As Integer
        Public RedRoad As Integer
        Public BlueRoad As Integer
        Public BlueWP As Int64
        Public RedWp As Int64
        Public RedCol As Integer
        Public BlueCol As Integer
        Public Manufacture As Single
    End Structure
    Public Structure Campaign
        Public Camp As String
        Public Battle As String
        Public Map As String
        Public Version As String
        Public RouteName As String
        Public DeZone As String
        Public RuZone As String
        Public DeNavalStop As String
        Public RuNavalStop As String
        Public DeHome As String
        Public RuHome As String
        Public DeSeaHome As String
        Public RuSeaHome As String
        Public dDate As Date
        Public EndDate As Date
    End Structure
    Public Structure Mission
        Public StartTime As Single
        Public EndTime As Single
        Public BCloudType As Integer
        Public WCloudType As Integer
        Public BaseSupp As Integer
        Public BaseSupply As Integer
        Public BaseDist As Integer
        Public BaseFuel As Integer 'Threshold below which fuel is imited
        Public FuelLimit As Integer 'Max fuel allowed when suppressed
        Public MaxFuel As Integer
        Public Convoy As Single
        Public Bridge As Integer
        Public SupplyLoad As String
        Public AirDropRange As Integer
        Public ParaDrop As Integer
        Public ParaRange As Integer
        Public LWindVelocity As Integer
        Public HWindVelocity As Integer
        Public LWindDirection As Integer
        Public HWindDirection As Integer
        Public LWindTop As Integer
        Public HWindtop As Integer
        Public BWindTurbulence As Integer
        Public WWindTurbulence As Integer
        Public BWindGust As Integer
        Public WWindGust As Integer
        Public LCloud As Integer
        Public HCloud As Integer
        Public RedRadar As String
        Public BlueRadar As String
        Public FactRepair As Single
        Public Contested As Single
    End Structure
    Public Structure Waypoint
        Public strFrom As String
        Public iFrom As Integer
        Public strTo As String
        Public iTo As Integer
        Public AxisX As Double
        Public AxisY As Double
        Public AxisH As Integer
        Public AlliedX As Double
        Public AlliedY As Double
        Public AlliedH As Integer
        Public Start As Long
        Public iEnd As Long
        Public FrmSpn As Integer
        Public ToSpn As Integer
        Public FrmStp As Integer
        Public ToStp As Integer
        Public AlliedSP As Integer
        Public AxisSP As Integer
    End Structure

    Public Structure Convoy
        Public Unit As String
        Public Size As Integer
        Public Fuel As Integer
        Public Supply As Integer
        Public Troops As Integer
        Public Columns As Integer
        Public Artillery As Integer
        Public Armor As Integer
        Public Amp As Integer
        Public BR As Integer
        Public Carrier As Integer
        Public MultUnits As Integer
    End Structure
    Public Structure Brid
        Public ID As String
        Public sFrom As String
        Public sTo As String
        Public iFrom As Integer
        Public iTo As Integer
        Public X As Double
        Public Y As Double
        Public Dead As String
    End Structure
    Public Structure BornPlaceClass
        Public X As Double
        Public Y As Double
        Public R As Double 'Radius
        Public Loc As String
        Public intLoc As Integer
        Public Side As Integer
        Public Aircraft As String
        Public Active As Boolean
        Public Type As Integer '0= airfield 1 = carrier 2 = seaplane base
    End Structure
    Public Structure Factory
        Public ID As String
        Public Unit As String
        Public Struct As Integer
        Public Active As Boolean
        Public X As Double
        Public Y As Double
        Public Head As Integer
        Public Loc As String
        Public intLoc As Integer
        Public Side As Integer
        Public Fuel As Integer
        Public Supply As Integer
        Public Col As Integer
        Public Troops As Integer
        Public Size As Integer
        Public Curr As Integer
        Public Repair As Integer
        Public Manufacture As Single 'Rate of Manufacture
        Public MaxMan As Single 'Maximium rate of Manufacture
        Public Other As String 'Middle part from plates.dcg file
    End Structure
    Public Structure WP
        Public X As Double
        Public Y As Double
        Public H As Integer
    End Structure
    Public Structure INI_Class
        Public sMainFolder As String
        Public sCampaign As String
        Public sServer As String
        Public sData As String
        Public sINIDate As String
        Public BornPlaceRadius As Integer  'BornPlace Radius
        Public ACSupply As Integer
        Public FactorySpawn As Single '% chance that a column will spawn at a factory
        Public ShipSpawn As Single '% chance that a ship will spawn
        Public TrainSpawn As Single '% chance that a train will spawn
        Public ColumnSpawn As Single '% chance that a ship will spawn
        Public sngDelay As Single
        Public sngRange As Single
        Public sngTankDly As Single
        Public sngTankRng As Single
        Public sngStaticSep As Single
        Public intMinFuel As Integer
        Public intMinSup As Integer
        Public intShowDestFact As Integer
        Public intRebuildCol As Integer
        Public iMovingDF As Integer 'Moving DF 0=off 1=in range 2 = all
        Public iMovingDist As Integer 'Moving DF range for setting 1  
        Public ColDelay As Integer
        Public TrainDelay As Integer
        Public ShipSep As Integer
        Public ShipSpeed As Single
        Public ColSpawn As Integer
        Public Daemon As Integer
        Public MisLength As Integer
        Public sExplosion As Single
    End Structure

    'REMOVED FOR APP.CONFIG
    'Public CFG_File As String = ""
    Public INI_File As String = ""
    'Public Const sDrive As String = "C:"
    'Public Const sFolder As String = "C:\AKA-FA Campaigns"
    'Public Const sFolder As String = "C:\FS Campaigns"
    Public Const ptCar As Integer = 1
    Public Const ptTank As Integer = 5
    Public Const ptAAA As Integer = 5
    Public Const ptShip As Integer = 10
    Public Const ptRocket As Integer = 10

    
    Public Sub Main(ByRef strCommand As String, _
                    ByRef strError As String, _
                    ByRef ini_settings As INI_Class)

        Dim Fact() As Factory 'Factories and other structures on the map
        Dim Stat() As Stationary
        Dim Train() As Column 'Trains in the column.dcg file
        Dim Infantry() As Column 'Infantry in .ird file
        Dim Locat() As Location 'Territory/Locations
        Dim Station() As Location 'Territory/Locations
        Dim Harbor() As Location 'Territory/Locations
        Dim Road() As Waypoint 'RDS FIle info
        Dim ShipRoute() As Waypoint 'SRD File info
        Dim Rail() As Waypoint 'RLS File info
        Dim Trail() As Waypoint 'IRD file info
        Dim Bldg() As Stationary
        Dim Pilot() As Plt
        Dim SeaWP() As WP 'SRD File
        Dim Rocket() As RocketType 'Rockets
        Dim CamSettings As New Campaign
        Dim Col() As Column 'Columns in the column.dcg file
        Dim Ship() As Column 'Ships in the column.dcg file
        Dim AC_New() As AC_Type 'Aircraft from the new Aircraft Type File
        Dim Squad() As Squad_Type 'Squadron
        Dim Weapon() As Weap
        Dim Radar() As Factory
        Dim SupplyAC() As AC_Supply
        Dim Transport() As Carry 'Tranport units
        Dim BornPlace() As BornPlaceClass 'Bornplace coordinates
        Dim Bridge() As Brid 'Bridges out
        Dim ConvoyInfo() As Convoy 'Convoy info
        Dim StructInfo() As Building 'Infor on types of structures
        Dim ManInfo() As Building 'Info on Factory Plate Types
        Dim Manufacture() As Factory 'Factory Plates from plates.dcg file

        Dim MissSettings As New Mission
        Dim Wind As Weather 'Weather Settings

        Dim RouteStart(2, 3) As Integer '(Side,Type) Integer of location
        Dim ConvoyVeh(,) As String 'Makeup of a convoys static objects
        Dim ConvoyMov(,) As String 'Makeup of a convoys moving objects
        Dim StructList(,) As String 'Makeup of a structure

        Dim House() As String 'Destroyed houses
        Dim strDebrief() As String
        Dim strBdgDown() As String
        Dim strACMove() As String
        Dim strFrontLine() As String
        Dim Chief() As String
        Dim ChiefMov() As String
        Dim ChiefRd() As String
        Dim DeadBridge() As String
        Dim RoadWp() As String 'RDS File
        Dim RailWP() As String 'RLS File 
        Dim TrailWP() As String 'IRD File data
        Dim ActiveBridge() As String
        Dim MDS() As String
        Dim MODS() As String
        Dim RedCountry() As String
        Dim BlueCountry() As String
        Dim ColLoc() As String
        Dim strErrFile As String

        Dim sEventDate As String = "" 'Eventlog date
        Dim sMissFolder As String = "" 'Mission Folder
        Dim bolError As Boolean = False

        Dim MisWeather As Integer
        Dim MisCloud As Integer
        Dim MisTime As Single 'Time Mission Starts
        Dim UseSquad As Integer
        Dim ProcEvent As Integer
        Dim GenMiss As Integer


        ReDim BornPlace(0)
        ReDim Bridge(0)
        ReDim Fact(0)
        ReDim Rocket(0)
        ReDim Squad(0)
        ReDim Stat(0)
        ReDim Col(0)
        ReDim Ship(0)
        ReDim Train(0)
        ReDim Locat(0)
        ReDim Harbor(0)
        ReDim Station(0)
        ReDim Road(0)
        ReDim ShipRoute(0)
        ReDim Rail(0)
        ReDim Trail(0)
        ReDim Bldg(0)
        ReDim strDebrief(0)
        ReDim strFrontLine(0)
        ReDim House(0)
        ReDim ColLoc(0)
        ReDim Infantry(0)
        ReDim strACMove(0)
        ReDim strBdgDown(0)
        ReDim Chief(0)
        ReDim ChiefMov(0)
        ReDim ChiefRd(0)
        ReDim DeadBridge(0)
        ReDim Pilot(0)
        ReDim RoadWp(0)
        ReDim RailWP(0)
        ReDim SeaWP(0)
        ReDim TrailWP(0)
        ReDim AC_New(0)
        ReDim Squad(0)
        ReDim Weapon(0)
        ReDim ActiveBridge(0)
        ReDim MDS(0)
        ReDim MODS(0)
        ReDim SupplyAC(0)
        ReDim Radar(0)
        ReDim RedCountry(0)
        ReDim BlueCountry(0)
        ReDim Transport(0)
        ReDim ConvoyVeh(20, 0)
        ReDim ConvoyMov(20, 0)
        ReDim ConvoyInfo(0)
        ReDim StructInfo(0)
        ReDim StructList(10, 0)
        ReDim ManInfo(0)
        ReDim Manufacture(0)

        'ChDrive(sDrive)
        'ChDir(sFolder)
        Randomize()
        'Set Arrays to help prevent subscript out of range errors
        strCommand = Command()
        GenMiss = 1
        ProcEvent = 1
        'Delete the error file
        strErrFile = ini_settings.sMainFolder & "\error.txt"
        If Dir(strErrFile) <> "" Then
            Kill(strErrFile)
        End If
        If InStr(strCommand, "-nomis") Then GenMiss = 0

        If bolError Then
            FoundError(strError, _
                       ini_settings.sMainFolder)
            Exit Sub
        End If
        'Process ini file

        sMissFolder = ini_settings.sServer & "\missions\net\dogfight\dcg"
        'Load Campaign
        LoadCampaign(bolError, _
                     strError, _
                     MisWeather, _
                     MisCloud, _
                     Wind, _
                     House, _
                     BornPlace, _
                     ConvoyVeh, _
                     ConvoyMov, _
                     ConvoyInfo, _
                     StructInfo, _
                     StructList, _
                     Fact, _
                     Rocket, _
                     CamSettings, _
                     MissSettings, _
                     Stat, _
                     Col, _
                     Ship, _
                     Train, _
                     Infantry, _
                     Locat, _
                     Station, _
                     Harbor, _
                     Road, _
                     ShipRoute, _
                     Rail, _
                     Trail, _
                     Bldg, _
                     strDebrief, _
                     RouteStart, _
                     RoadWp, _
                     RailWP, _
                     SeaWP, _
                     TrailWP, _
                     AC_New, _
                     Squad, _
                     UseSquad, _
                     Weapon, _
                     ActiveBridge, _
                     MDS, _
                     MODS, _
                     SupplyAC, _
                     Radar, _
                     RedCountry, _
                     BlueCountry, _
                     ini_settings, _
                     MisTime, _
                     ManInfo, _
                     Manufacture)
        If bolError Then
            FoundError(strError, _
                       ini_settings.sMainFolder)
            Exit Sub
        End If

        'Process Eventlog
        ProcessMission(bolError, _
                       strError, _
                       sEventDate, _
                       BornPlace, _
                       Bridge, _
                       Fact, _
                       Rocket, _
                        CamSettings, _
                        MissSettings, _
                        Stat, _
                        Col, _
                        Ship, _
                        Train, _
                        Infantry, _
                        Locat, _
                        Station, _
                        Harbor, _
                        strDebrief, _
                        strFrontLine, _
                        strBdgDown, _
                        ProcEvent, _
                        Pilot, _
                        Squad, _
                        ActiveBridge, _
                        SupplyAC, _
                        Radar, _
                        ini_settings, _
                        Manufacture)
        If bolError Then
            FoundError(strError, _
                       ini_settings.sMainFolder)
            Exit Sub
        End If
        If ProcEvent > 0 Then
            'Prepare for Next Mission
            PrepareNextMission(bolError, _
                                strError, _
                                ColLoc, _
                                MisWeather, _
                                MisCloud, _
                                Wind, _
                                BornPlace, _
                                Bridge, _
                                Fact, _
                                Rocket, _
                                CamSettings, _
                                MissSettings, _
                                Stat, _
                                Col, _
                                Ship, _
                                Train, _
                                Infantry, _
                                Locat, _
                                Station, _
                                Harbor, _
                                Road, _
                                ShipRoute, _
                                Rail, _
                                Trail, _
                                strDebrief, _
                                RouteStart, _
                                AC_New, _
                                Squad, _
                                UseSquad, _
                                Radar, _
                                ini_settings, _
                                MisTime, _
                                Weapon, _
                                Manufacture)
            If bolError Then
                FoundError(strError, _
                           ini_settings.sMainFolder)
                Exit Sub
            End If
            'Generate Filers for Next mission
            GenFiles(bolError, _
                     strError, _
                     sEventDate, _
                     ColLoc, _
                     MisWeather, _
                     MisCloud, _
                     Wind, _
                     Bridge, _
                      Fact, _
                     Rocket, _
                     CamSettings, _
                     MissSettings, _
                     Stat, _
                     Col, _
                     Ship, _
                     Train, _
                     Infantry, _
                     Locat, _
                     Station, _
                     Harbor, _
                     strDebrief, _
                     strFrontLine, _
                     strACMove, _
                     strBdgDown, _
                     AC_New, _
                     Squad, _
                    UseSquad, _
                    SupplyAC, _
                    Radar, _
                    RedCountry, _
                    BlueCountry, _
                    ini_settings, _
                    MisTime, _
                    Manufacture)
            If bolError Then
                FoundError(strError, _
                           ini_settings.sMainFolder)
                Exit Sub
            End If
        End If
        If GenMiss > 0 Then
            GenMissFiles(bolError, _
                         strError, _
                         MisWeather, _
                         MisCloud, _
                         sMissFolder, _
                         Transport, _
                         Wind, _
                         House, _
                         BornPlace, _
                         ConvoyVeh, _
                         ConvoyInfo, _
                         StructInfo, _
                         StructList, _
                         Fact, _
                         Rocket, _
                         CamSettings, _
                         MissSettings, _
                         Stat, _
                         Col, _
                         Ship, _
                         Train, _
                         Infantry, _
                         Locat, _
                         Station, _
                         Harbor, _
                         Road, _
                         ShipRoute, _
                         Rail, _
                         Trail, _
                         Bldg, _
                         strDebrief, _
                         strFrontLine, _
                         strACMove, _
                         strBdgDown, _
                         Chief, _
                         ChiefMov, _
                         ChiefRd, _
                         DeadBridge, _
                         RoadWp, _
                         RailWP, _
                         SeaWP, _
                         TrailWP, _
                         Squad, _
                         UseSquad, _
                         Weapon, _
                         MDS, _
                         MODS, _
                         SupplyAC, _
                         Radar, _
                         RedCountry, _
                         BlueCountry, _
                         ini_settings, _
                         MisTime, _
                         Manufacture)
            If bolError Then
                FoundError(strError, _
                           ini_settings.sMainFolder)
                Exit Sub
            End If
        End If
        'Debug
        GenDebug(ini_settings.sMainFolder, _
                 sEventDate, _
                 BornPlace, _
                 Bridge, _
                 StructInfo, _
                 Fact, _
                 Rocket, _
                 Stat, _
                 Col, _
                 Ship, _
                 Train, _
                 Infantry, _
                 Locat, _
                 Station, _
                 Harbor, _
                 Road, _
                 ShipRoute, _
                 Rail, _
                 strDebrief, _
                 strFrontLine, _
                 strACMove, _
                 GenMiss, _
                 ProcEvent, _
                 Squad, _
                 Radar)
    End Sub
    Public Sub Proc_CFG(ByRef bolerror As Boolean, _
                        ByRef strerror As String, _
                        ByRef CFG_File As String, _
                        ByRef INI_File As String)
        Dim strInput As String = ""
        Dim intStart As Integer
        Dim strErrFile As String = ""
        Dim filereader As IO.StreamReader
        bolerror = False
        If My.Computer.FileSystem.FileExists(CFG_File) Then
            filereader = My.Computer.FileSystem.OpenTextFileReader(CFG_File)
            Do Until filereader.EndOfStream
                strInput = Trim(filereader.ReadLine)
                intStart = InStr(strInput, "INI_FILE=")
                If intStart > 0 Then
                    intStart = InStr(strInput, "=") + 1
                    INI_File = Trim(Mid(strInput, intStart))
                End If

            Loop
            filereader.Close()
        End If

        If INI_File = "" Then
            bolerror = True
            strerror = "No INI File in Config!"
        Else
            frmMain.tbINI_File.Text = ini_file
        End If
    End Sub
    Public Sub Proc_INI(ByRef bolerror As Boolean, _
                        ByRef strerror As String, _
                        ByRef INI_Settings As INI_Class)
        Dim strInput As String = ""
        Dim intStart As Integer
        Dim strErrFile As String = ""
        Dim filereader As IO.StreamReader
        bolerror = False

        With INI_Settings
            .ACSupply = 1
            .MisLength = 90
            .ColDelay = 1
            .TrainDelay = 1
            .ShipSpeed = 2
            .ShipSep = 250
            .ColSpawn = 6
            .sngDelay = 0.5
            .sngRange = 500
            .sCampaign = ""
            .sINIDate = ""
            .BornPlaceRadius = 500
            .intMinFuel = 5
            .intShowDestFact = 1
            .iMovingDist = 50
            .sngStaticSep = 20


            If Dir(INI_File) = "" Then
                bolerror = True
                strerror = "Cannot find INI file!"
                Exit Sub
            End If



            If My.Computer.FileSystem.FileExists(INI_File) Then
                filereader = My.Computer.FileSystem.OpenTextFileReader(INI_File)
                Do Until filereader.EndOfStream
                    strInput = Trim(filereader.ReadLine)
                    intStart = InStr(strInput, "Campaign=")
                    If intStart > 0 Then
                        intStart = InStr(strInput, "=") + 1
                        .sCampaign = Trim(Mid(strInput, intStart))
                    End If
                    intStart = InStr(strInput, "IL2Path=")
                    If intStart > 0 Then
                        intStart = InStr(strInput, "=") + 1
                        .sServer = Trim(Mid(strInput, intStart))
                    End If
                    intStart = InStr(strInput, "LogFileDate=")
                    If intStart > 0 Then
                        intStart = intStart + 12
                        .sINIDate = Trim(Mid(strInput, intStart))
                    End If
                    intStart = InStr(strInput, "DataFiles=")
                    If intStart > 0 Then
                        intStart = intStart + 10
                        .sData = Trim(Mid(strInput, intStart))
                    End If
                Loop
                filereader.Close()
            End If

            If .sCampaign = "" Then
                bolerror = True
                strerror = "No Campaign in INI file!"
            End If

        End With
    End Sub
    Public Sub FoundError(ByRef strerror As String, _
                          ByRef smainfolder As String)
        Dim strErrFile As String = ""
        Dim sb As New StringBuilder
        strErrFile = smainfolder & "\error.txt"
        sb.AppendLine(strerror)
        FileOpen(1, strErrFile, OpenMode.Output, OpenAccess.Write, OpenShare.Shared)
        Print(1, sb.ToString)
        FileClose(1)
        
    End Sub
    Public Sub LoadCampaign(ByRef bolError As Boolean, _
                            ByRef strError As String, _
                            ByRef MisWeather As Integer, _
                            ByRef MisCloud As Integer, _
                            ByRef Wind As Weather, _
                            ByRef House() As String, _
                            ByRef BornPlace() As BornPlaceClass, _
                            ByRef ConvoyVeh(,) As String, _
                            ByRef ConvoyMov(,) As String, _
                            ByRef ConvoyInfo() As Convoy, _
                            ByRef StructInfo() As Building, _
                            ByRef StructList(,) As String, _
                            ByRef Fact() As Factory, _
                            ByRef Rocket() As RocketType, _
                            ByRef camsettings As Campaign, _
                            ByRef MissSettings As Mission, _
                            ByRef Stat() As Stationary, _
                            ByRef Col() As Column, _
                            ByRef Ship() As Column, _
                            ByRef Train() As Column, _
                            ByRef Infantry() As Column, _
                            ByRef Locat() As Location, _
                            ByRef Station() As Location, _
                            ByRef Harbor() As Location, _
                            ByRef Road() As Waypoint, _
                            ByRef ShipRoute() As Waypoint, _
                            ByRef Rail() As Waypoint, _
                            ByRef Trail() As Waypoint, _
                            ByRef Bldg() As Stationary, _
                            ByRef strDebrief() As String, _
                            ByRef RouteStart(,) As Integer, _
                            ByRef RoadWp() As String, _
                            ByRef RailWP() As String, _
                            ByRef SeaWP() As WP, _
                            ByRef TrailWP() As String, _
                            ByRef AC_New() As AC_Type, _
                            ByRef Squad() As Squad_Type, _
                            ByRef UseSquad As Integer, _
                            ByRef Weapon() As Weap, _
                            ByRef ActiveBridge() As String, _
                            ByRef MDS() As String, _
                            ByRef MODS() As String, _
                            ByRef SupplyAC() As AC_Supply, _
                            ByRef Radar() As Factory, _
                            ByRef RedCountry() As String, _
                            ByRef BlueCountry() As String, _
                            ByRef INI_Settings As INI_Class, _
                            ByRef MisTime As Single, _
                            ByRef ManInfo() As Building, _
                            ByRef Manufacture() As Factory)
        LoadCampFile(bolError, _
                     strError, _
                     camsettings, _
                     MissSettings, _
                     SupplyAC, _
                     RedCountry, _
                     BlueCountry, _
                     INI_Settings)
        If bolError Then Exit Sub
        LoadConditionsFile(bolError, _
                           strError, _
                           MisWeather, _
                           MisCloud, _
                           Wind, _
                           INI_Settings, _
                           MisTime)
        If bolError Then Exit Sub

        'Route Files
        LoadRDSFile(bolError, _
                    strError, _
                    camsettings, _
                    Locat, _
                    Road, _
                    ShipRoute, _
                    RoadWp, _
                    INI_Settings)
        If bolError Then Exit Sub
        LoadIRDFile(camsettings, _
                    Locat, _
                    Trail, _
                    TrailWP, _
                    INI_Settings)
        LoadRLSFile(bolError, _
                    strError, _
                    camsettings, _
                    Station, _
                    Rail, _
                    RailWP, _
                    INI_Settings)
        If bolError Then Exit Sub
        LoadSRDFile(bolError, _
                    strError, _
                    camsettings, _
                    Harbor, _
                    ShipRoute, _
                    SeaWP, _
                    INI_Settings)
        If bolError Then Exit Sub
        FindRoadLoc(bolError, _
                    strError, _
                    Locat, _
                    Station, _
                    Harbor)
        If bolError Then Exit Sub
        LoadTerritoryFile(bolError, _
                          strError, _
                          MissSettings, _
                          Locat, _
                          Station, _
                          Harbor, _
                          INI_Settings)
        If bolError Then Exit Sub
        FindRouteStart(bolError, _
                        strError, _
                        camsettings, _
                        Locat, _
                        Road, _
                        ShipRoute, _
                        Rail, _
                        RouteStart)
        If bolError Then Exit Sub
        LoadBornPlaceFile(bolError, _
                          strError, _
                          BornPlace, _
                          camsettings, _
                          Locat, _
                          INI_Settings)

        'Object makeup files
        If bolError Then Exit Sub

        If bolError Then Exit Sub
        LoadConvoyFile(bolError, _
                       strError, _
                       ConvoyVeh, _
                       ConvoyMov, _
                       ConvoyInfo, _
                       INI_Settings)
        If bolError Then Exit Sub
        LoadStructFile(bolError, _
                       strError, _
                        StructInfo, _
                        StructList, _
                        INI_Settings)
        If bolError Then Exit Sub
        LoadFactFile(bolError, _
                     strError, _
                     StructInfo, _
                     Fact, _
                     Locat, _
                     strDebrief, _
                     INI_Settings)
        If bolError Then Exit Sub
        LoadManufactureFile(ManInfo, _
                            INI_Settings)
        If ManInfo.Length > 1 Then
            LoadPlateFile(Manufacture, _
                          ManInfo, _
                          Locat, _
                          INI_Settings)
        End If

        LoadRadarFile(StructInfo, _
                      Locat, _
                      strDebrief, _
                      Radar, _
                      strError, _
                      INI_Settings)
        'Ground Object FIles
        LoadStatFile(bolError, _
                     strError, _
                     BornPlace, _
                     Stat, _
                     Locat, _
                     INI_Settings)
        If bolError Then Exit Sub
        LoadRocketFile(bolError, _
                       strError, _
                       ConvoyInfo, _
                       Rocket, _
                       Locat, _
                       INI_Settings)
        If bolError Then Exit Sub
        LoadColumnFile(bolError, _
                       strError, _
                       BornPlace, _
                       ConvoyInfo, _
                       Col, _
                       Ship, _
                       Train, _
                       Infantry, _
                       Locat, _
                       Station, _
                       Harbor, _
                        INI_Settings)
        If bolError Then Exit Sub
        LoadBldgFile(bolError, _
                     strError, _
                     Locat, _
                     Bldg, _
                     INI_Settings)
        If bolError Then Exit Sub
        LoadHouseFile(bolError, _
                      strError, _
                      House, _
                      INI_Settings)
        If bolError Then Exit Sub
        LoadActiveBridge(ActiveBridge, _
                         INI_Settings)

        'Aircraft Files
        LoadAircraftFile(BornPlace, _
                         MissSettings, _
                         AC_New, _
                         Squad, _
                         UseSquad, _
                         INI_Settings, _
                            bolError, _
                            strError)
        SupplyAircraft(AC_New, _
                       SupplyAC)

        If bolError Then Exit Sub
        LoadWeaponFile(bolError, _
                       strError, _
                       Squad, _
                       Weapon, _
                       INI_Settings, _
                       AC_New)
        If bolError Then Exit Sub
        CleanUpStat(bolError, _
                    strError, _
                    Stat, _
                    Locat)
        If bolError Then Exit Sub

        'Other Files
        LoadMDS(MDS, _
                INI_Settings)
        LoadMODS(MODS, _
                 INI_Settings)
    End Sub
    Public Sub LoadCampFile(ByRef bolerror As Boolean, _
                    ByRef strerror As String, _
                    ByRef camsettings As Campaign, _
                    ByRef MissSettings As Mission, _
                    ByRef SupplyAC() As AC_Supply, _
                    ByRef RedCountry() As String, _
                    ByRef BlueCountry() As String, _
                    ByRef ini_settings As INI_Class)
        Dim strCamFile As String
        Dim strInput As String
        Dim strValue As String
        Dim intStart As Integer
        Dim filereader As IO.StreamReader
        strCamFile = ini_settings.sCampaign & "\campaign.dcg"
        If Dir(strCamFile) = "" Then
            bolerror = True
            strerror = "Cannot find campaign file!"
            Exit Sub
        End If
        With MissSettings
            .Convoy = 0.5
            .Bridge = 2
            .LCloud = 0
            .HCloud = 1500
            .FactRepair = 0.25
            .SupplyLoad = "none"
            .AirDropRange = 1
            .BaseFuel = 5
            .FuelLimit = 100
            .MaxFuel = 100
            .Contested = 0.2
        End With
        ini_settings.sExplosion = 1
        strValue = ""
        If My.Computer.FileSystem.FileExists(strCamFile) Then
            filereader = My.Computer.FileSystem.OpenTextFileReader(strCamFile)
            Do Until filereader.EndOfStream
                strInput = Trim(filereader.ReadLine)
                If InStr(strInput, "Campaign=") Then
                    FindValue(strInput, strValue)
                    camsettings.Camp = Trim(strValue)
                End If
                If InStr(strInput, "Battle=") Then
                    FindValue(strInput, strValue)
                    camsettings.Battle = Trim(strValue)
                End If
                If InStr(strInput, "Map=") Then
                    FindValue(strInput, strValue)
                    camsettings.Map = Trim(strValue)
                End If
                If InStr(strInput, "Version=") Then
                    FindValue(strInput, strValue)
                    camsettings.Version = Trim(strValue)
                    If camsettings.Version <> "" Then
                        camsettings.RouteName = camsettings.Map
                        camsettings.Map = camsettings.Map & "/" & camsettings.Version
                    End If
                End If
                If InStr(strInput, "Route=") Then
                    FindValue(strInput, strValue)
                    camsettings.RouteName = Trim(strValue)
                End If
                If InStr(strInput, "BlueSpawn=") Then
                    FindValue(strInput, strValue)
                    camsettings.DeZone = Trim(strValue)
                End If
                If InStr(strInput, "RedSpawn=") Then
                    FindValue(strInput, strValue)
                    camsettings.RuZone = Trim(strValue)
                End If
                If InStr(strInput, "RedNavalStop=") Then
                    FindValue(strInput, strValue)
                    camsettings.RuNavalStop = Trim(strValue)
                End If
                If InStr(strInput, "BlueNavalStop=") Then
                    FindValue(strInput, strValue)
                    camsettings.DeNavalStop = Trim(strValue)
                End If
                If InStr(strInput, "BlueHomeBase=") Then
                    FindValue(strInput, strValue)
                    camsettings.DeHome = Trim(strValue)
                End If
                If InStr(strInput, "RedSeaHomeBase=") Then
                    FindValue(strInput, strValue)
                    camsettings.RuSeaHome = Trim(strValue)
                End If
                If InStr(strInput, "BlueSeaHomeBase=") Then
                    FindValue(strInput, strValue)
                    camsettings.DeSeaHome = Trim(strValue)
                End If
                If InStr(strInput, "RedHomeBase=") Then
                    FindValue(strInput, strValue)
                    camsettings.RuHome = Trim(strValue)
                End If
                If InStr(strInput, "Date=") Then
                    FindValue(strInput, strValue)
                    camsettings.dDate = Trim(strValue)
                End If
                If InStr(strInput, "End=") Then
                    FindValue(strInput, strValue)
                    camsettings.EndDate = Trim(strValue)
                End If

                intStart = InStr(strInput, "StartTime=")
                If intStart > 0 Then
                    FindValue(strInput, strValue)
                    MissSettings.StartTime = Val(strValue)
                End If
                intStart = InStr(strInput, "EndTime=")
                If intStart > 0 Then
                    FindValue(strInput, strValue)
                    MissSettings.EndTime = Val(strValue)
                End If

                intStart = InStr(strInput, "BCloudType=")
                If intStart > 0 Then
                    FindValue(strInput, strValue)
                    MissSettings.BCloudType = Int(Val(strValue))
                End If
                intStart = InStr(strInput, "WCloudType=")
                If intStart > 0 Then
                    FindValue(strInput, strValue)
                    MissSettings.WCloudType = Int(Val(strValue))
                End If
                intStart = InStr(strInput, "BaseSuppression=")
                If intStart > 0 Then
                    FindValue(strInput, strValue)
                    MissSettings.BaseSupp = Int(Val(strValue))
                End If
                intStart = InStr(strInput, "BaseSupply=")
                If intStart > 0 Then
                    FindValue(strInput, strValue)
                    MissSettings.BaseSupply = Int(Val(strValue))
                End If
                intStart = InStr(strInput, "BaseDistance=")
                If intStart > 0 Then
                    FindValue(strInput, strValue)
                    MissSettings.BaseDist = Int(Val(strValue))
                End If

                intStart = InStr(strInput, "BaseFuel=")
                If intStart > 0 Then
                    FindValue(strInput, strValue)
                    MissSettings.BaseFuel = Int(Val(strValue))
                End If
                intStart = InStr(strInput, "FuelLimit=")
                If intStart > 0 Then
                    FindValue(strInput, strValue)
                    MissSettings.FuelLimit = Int(Val(strValue))
                End If

                intStart = InStr(strInput, "MaxFuel=")
                If intStart > 0 Then
                    FindValue(strInput, strValue)
                    MissSettings.MaxFuel = Int(Val(strValue))
                    If MissSettings.MaxFuel > 100 Then MissSettings.MaxFuel = 100
                    If MissSettings.MaxFuel < 10 Then MissSettings.MaxFuel = 10
                End If

                intStart = InStr(strInput, "Bridge=")
                If intStart > 0 Then
                    FindValue(strInput, strValue)
                    MissSettings.Bridge = Int(Val(strValue))
                End If
                intStart = InStr(strInput, "Convoy=")
                If intStart > 0 Then
                    FindValue(strInput, strValue)
                    MissSettings.Convoy = Val(strValue)
                End If
                intStart = InStr(strInput, "SupplyAC=")
                If intStart > 0 Then
                    intStart = InStr(strInput, "=")
                    If Len(strInput) > intStart Then
                        strValue = Trim(Mid(strInput, intStart + 1))
                        If strValue <> "" Then
                            intStart = InStr(strValue, ",")
                            If intStart > 0 Then
                                If intStart > 1 Then
                                    ReDim Preserve SupplyAC(SupplyAC.Length)
                                    SupplyAC(SupplyAC.Length - 1).Coop = Trim(Left(strValue, intStart - 1))
                                    If Len(strValue) > intStart Then
                                        SupplyAC(SupplyAC.Length - 1).Supply = Val(Mid(strValue, intStart + 1))
                                        If SupplyAC(SupplyAC.Length - 1).Supply < 1 Then SupplyAC(SupplyAC.Length - 1).Supply = 5
                                    Else
                                        SupplyAC(SupplyAC.Length - 1).Supply = 5
                                    End If
                                End If
                            Else
                                ReDim Preserve SupplyAC(SupplyAC.Length)
                                SupplyAC(SupplyAC.Length - 1).Coop = strValue
                                SupplyAC(SupplyAC.Length - 1).Supply = 5
                            End If
                        End If
                    End If
                End If

                intStart = InStr(strInput, "SupplyLoad=")
                If intStart > 0 Then
                    FindValue(strInput, strValue)
                    MissSettings.SupplyLoad = Trim(strValue)
                    If MissSettings.SupplyLoad = "" Then MissSettings.SupplyLoad = "none"
                End If
                intStart = InStr(strInput, "AirDropRange=")
                If intStart > 0 Then
                    FindValue(strInput, strValue)
                    MissSettings.AirDropRange = Int(Val(strValue))
                    If MissSettings.AirDropRange < 1 Then MissSettings.AirDropRange = 1
                End If

                intStart = InStr(strInput, "ParaDrop=")
                If intStart > 0 Then
                    FindValue(strInput, strValue)
                    MissSettings.ParaDrop = Int(Val(strValue))
                    If MissSettings.ParaDrop <> 1 Then MissSettings.ParaDrop = 0
                End If
                intStart = InStr(strInput, "ParaRange=")
                If intStart > 0 Then
                    FindValue(strInput, strValue)
                    MissSettings.ParaRange = Int(Val(strValue))
                    If MissSettings.ParaRange < 1 Then MissSettings.ParaRange = 1
                End If

                intStart = InStr(strInput, "LWindVelocity=")
                If intStart > 0 Then
                    FindValue(strInput, strValue)
                    MissSettings.LWindVelocity = Int(Val(strValue))
                End If
                intStart = InStr(strInput, "HWindVelocity=")
                If intStart > 0 Then
                    FindValue(strInput, strValue)
                    MissSettings.HWindVelocity = Int(Val(strValue))
                End If
                intStart = InStr(strInput, "LWindDirection=")
                If intStart > 0 Then
                    FindValue(strInput, strValue)
                    MissSettings.LWindDirection = Int(Val(strValue))
                End If
                intStart = InStr(strInput, "HWindDirection=")
                If intStart > 0 Then
                    FindValue(strInput, strValue)
                    MissSettings.HWindDirection = Int(Val(strValue))
                End If
                intStart = InStr(strInput, "LWindTop=")
                If intStart > 0 Then
                    FindValue(strInput, strValue)
                    MissSettings.LWindTop = Int(Val(strValue))
                End If
                intStart = InStr(strInput, "HWindTop=")
                If intStart > 0 Then
                    FindValue(strInput, strValue)
                    MissSettings.HWindtop = Int(Val(strValue))
                End If
                intStart = InStr(strInput, "BWindTurbulence=")
                If intStart > 0 Then
                    FindValue(strInput, strValue)
                    MissSettings.BWindTurbulence = Int(Val(strValue))
                End If
                intStart = InStr(strInput, "WWindTurbulence=")
                If intStart > 0 Then
                    FindValue(strInput, strValue)
                    MissSettings.WWindTurbulence = Int(Val(strValue))
                End If
                intStart = InStr(strInput, "BWindGust=")
                If intStart > 0 Then
                    FindValue(strInput, strValue)
                    MissSettings.BWindGust = Int(Val(strValue))
                End If
                intStart = InStr(strInput, "WWindGust=")
                If intStart > 0 Then
                    FindValue(strInput, strValue)
                    MissSettings.WWindGust = Int(Val(strValue))
                End If
                intStart = InStr(strInput, "LCloudAlt=")
                If intStart > 0 Then
                    FindValue(strInput, strValue)
                    MissSettings.LCloud = Int(Val(strValue))
                End If
                intStart = InStr(strInput, "HCloudAlt=")
                If intStart > 0 Then
                    FindValue(strInput, strValue)
                    MissSettings.HCloud = Int(Val(strValue))
                End If
                intStart = InStr(strInput, "FactRepair=")
                If intStart > 0 Then
                    FindValue(strInput, strValue)
                    MissSettings.FactRepair = Val(strValue)
                End If
                'BASES
                intStart = InStr(strInput, "RedRadar=")
                If intStart > 0 Then
                    FindValue(strInput, strValue)
                    MissSettings.RedRadar = Trim(strValue)
                End If
                intStart = InStr(strInput, "RedCountry=")
                If intStart > 0 Then
                    FindValue(strInput, strValue)
                    ReDim Preserve RedCountry(RedCountry.Length)
                    RedCountry(RedCountry.Length - 1) = Trim(strValue)
                End If
                intStart = InStr(strInput, "BlueRadar=")
                If intStart > 0 Then
                    FindValue(strInput, strValue)
                    MissSettings.BlueRadar = Trim(strValue)
                End If
                intStart = InStr(strInput, "BlueCountry=")
                If intStart > 0 Then
                    FindValue(strInput, strValue)
                    ReDim Preserve BlueCountry(BlueCountry.Length)
                    BlueCountry(BlueCountry.Length - 1) = Trim(strValue)
                End If
                intStart = InStr(strInput, "Contested=")
                If intStart > 0 Then
                    FindValue(strInput, strValue)
                    MissSettings.Contested = Math.Abs(Val(strValue))
                    If MissSettings.Contested > 0.49 Then MissSettings.Contested = 0.2
                    If MissSettings.Contested < 0.001 Then MissSettings.Contested = 0.2
                End If

                'INI Settings
                With ini_settings
                    
                    intStart = InStr(strInput, "BornPlaceRadius=")
                    If intStart > 0 Then
                        intStart = intStart + 16
                        .BornPlaceRadius = Int(Mid(strInput, intStart))
                    End If
                    intStart = InStr(strInput, "AircraftSupply=")
                    If intStart > 0 Then
                        intStart = InStr(strInput, "=") + 1
                        .ACSupply = Int(Mid(strInput, intStart))
                    End If
                    intStart = InStr(strInput, "FactorySpawn=")
                    If intStart > 0 Then
                        intStart = InStr(strInput, "=") + 1
                        .FactorySpawn = Val(Mid(strInput, intStart))
                    End If
                    intStart = InStr(strInput, "TrainSpawn=")
                    If intStart > 0 Then
                        intStart = InStr(strInput, "=") + 1
                        .TrainSpawn = Val(Mid(strInput, intStart))
                    End If
                    intStart = InStr(strInput, "ShipSpawn=")
                    If intStart > 0 Then
                        intStart = InStr(strInput, "=") + 1
                        .ShipSpawn = Val(Mid(strInput, intStart))
                    End If
                    intStart = InStr(strInput, "ColumnSpawn=")
                    If intStart > 0 Then
                        intStart = InStr(strInput, "=") + 1
                        .ColumnSpawn = Val(Mid(strInput, intStart))
                    End If
                    intStart = InStr(strInput, "Range=")
                    If intStart > 0 Then
                        intStart = InStr(strInput, "=") + 1
                        .sngRange = Val(Mid(strInput, intStart))
                    End If
                    intStart = InStr(strInput, "Delay=")
                    If intStart > 0 Then
                        intStart = InStr(strInput, "=") + 1
                        .sngDelay = Val(Mid(strInput, intStart))
                    End If
                    intStart = InStr(strInput, "TankDly=")
                    If intStart > 0 Then
                        intStart = InStr(strInput, "=") + 1
                        .sngTankDly = Val(Mid(strInput, intStart))
                    End If
                    intStart = InStr(strInput, "TankRng=")
                    If intStart > 0 Then
                        intStart = InStr(strInput, "=") + 1
                        .sngTankRng = Val(Mid(strInput, intStart))
                    End If
                    intStart = InStr(strInput, "StaticSep=")
                    If intStart > 0 Then
                        intStart = InStr(strInput, "=") + 1
                        .sngStaticSep = Val(Mid(strInput, intStart))
                        If .sngStaticSep < 10 Then .sngStaticSep = 10
                        If .sngStaticSep > 100 Then .sngStaticSep = 100
                    End If
                    intStart = InStr(strInput, "MinFuel=")
                    If intStart > 0 Then
                        intStart = InStr(strInput, "=") + 1
                        .intMinFuel = Int(Val(Mid(strInput, intStart)))
                    End If
                    intStart = InStr(strInput, "MinSupply=")
                    If intStart > 0 Then
                        intStart = InStr(strInput, "=") + 1
                        .intMinSup = Int(Val(Mid(strInput, intStart)))
                    End If
                    intStart = InStr(strInput, "ShowDestFact=")
                    If intStart > 0 Then
                        intStart = InStr(strInput, "=") + 1
                        .intShowDestFact = Int(Val(Mid(strInput, intStart)))
                        If .intShowDestFact > 0 Then
                            .intShowDestFact = 1
                        Else
                            .intShowDestFact = 0
                        End If
                    End If
                    intStart = InStr(strInput, "RebuildColumn=")
                    If intStart > 0 Then
                        intStart = InStr(strInput, "=") + 1
                        .intRebuildCol = Int(Val(Mid(strInput, intStart)))
                        If .intRebuildCol > 0 Then
                            .intRebuildCol = 1
                        Else
                            .intRebuildCol = 0
                        End If
                    End If
                    intStart = InStr(strInput, "MovingDF=")
                    If intStart > 0 Then
                        intStart = InStr(strInput, "=") + 1
                        .iMovingDF = Int(Val(Mid(strInput, intStart)))
                        If .iMovingDF < 1 Then
                            .iMovingDF = 0
                        End If
                    End If
                    intStart = InStr(strInput, "MovingDist=")
                    If intStart > 0 Then
                        intStart = InStr(strInput, "=") + 1
                        .iMovingDist = Int(Val(Mid(strInput, intStart)))
                        If .iMovingDist < 0 Then
                            .iMovingDist = 0
                        End If
                    End If
                    intStart = InStr(strInput, "ColDelay=")
                    If intStart > 0 Then
                        intStart = InStr(strInput, "=") + 1
                        .ColDelay = Int(Val(Mid(strInput, intStart)))
                    End If
                    intStart = InStr(strInput, "TrainDelay=")
                    If intStart > 0 Then
                        intStart = InStr(strInput, "=") + 1
                        .TrainDelay = Int(Val(Mid(strInput, intStart)))
                    End If
                    intStart = InStr(strInput, "ShipSpeed=")
                    If intStart > 0 Then
                        intStart = InStr(strInput, "=") + 1
                        .ShipSpeed = Val(Mid(strInput, intStart))
                        If .ShipSpeed < 1 Then
                            .ShipSpeed = 2
                        End If
                    End If
                    intStart = InStr(strInput, "ShipSep=")
                    If intStart > 0 Then
                        intStart = InStr(strInput, "=") + 1
                        .ShipSep = Int(Val(Mid(strInput, intStart)))
                        If .ShipSep < 1 Then
                            .ShipSep = 250
                        End If
                    End If

                    
                    intStart = InStr(strInput, "MissionLength=")
                    If intStart > 0 Then
                        intStart = InStr(strInput, "=") + 1
                        .MisLength = Int(Val(Mid(strInput, intStart)))
                        If .MisLength < 1 Then
                            .MisLength = 90
                        End If
                    End If
                    intStart = InStr(strInput, "ColSpawn=")
                    If intStart > 0 Then
                        intStart = InStr(strInput, "=") + 1
                        .ColSpawn = Int(Val(Mid(strInput, intStart)))
                    End If
                    intStart = InStr(strInput, "Explosion=")
                    If intStart > 0 Then
                        intStart = InStr(strInput, "=") + 1
                        .sExplosion = Val(Mid(strInput, intStart))
                    End If
                End With
            Loop
            filereader.Close()
            With MissSettings
                If .LWindVelocity < 0 Then .LWindVelocity = 0
                If .LWindVelocity > 70 Then .LWindVelocity = 70
                If .HWindVelocity > 70 Then .HWindVelocity = 70
                If .HWindVelocity < .LWindVelocity Then .HWindVelocity = .LWindVelocity

                If .LWindDirection < 0 Then .LWindDirection = 0
                If .LWindDirection > 359 Then .LWindDirection = 359
                If .HWindDirection > 359 Then .HWindDirection = 359
                If .HWindDirection < .LWindDirection Then .HWindDirection = .LWindDirection

                If .LWindTop < 500 Then .LWindTop = 500
                If .LWindTop > 10000 Then .LWindTop = 10000
                If .HWindtop > 10000 Then .HWindtop = 10000
                If .HWindtop < .LWindTop Then .HWindtop = .LWindTop

                If .BWindTurbulence < 0 Then .BWindTurbulence = 0
                If .BWindTurbulence > 6 Then .BWindTurbulence = 6
                If .WWindTurbulence > 6 Then .WWindTurbulence = 6
                If .WWindTurbulence < .BWindTurbulence Then .WWindTurbulence = .BWindTurbulence

                If .BWindGust < 0 Then .BWindGust = 0
                If .BWindGust > 6 Then .BWindGust = 6
                If .WWindGust > 6 Then .WWindGust = 6
                If .WWindGust < .BWindGust Then .WWindGust = .BWindGust

                If .LCloud < 0 Then .BWindGust = 0
                If .LCloud > 10000 Then .LCloud = 10000
                If .HCloud > 10000 Then .HCloud = 10000
                If .HCloud < .LCloud Then .HCloud = .LCloud

            End With
        End If
    End Sub
    Public Sub FindValue(ByRef strInput As String, _
                            ByRef strValue As String)
        Dim intStart As Integer
        intStart = InStr(strInput, "=") + 1
        If intStart <= Len(strInput) Then
            strValue = Mid(strInput, intStart)
        Else
            strValue = ""
        End If
    End Sub
   
    Public Sub LoadStatFile(ByRef bolerror As Boolean, _
                        ByRef strerror As String, _
                        ByRef BornPlace() As BornPlaceClass, _
                        ByRef Stat() As Stationary, _
                        ByRef Locat() As Location, _
                        ByRef INI_Settings As INI_Class)

        Dim strStatFile As String
        Dim strInput As String
        Dim intPos As Integer
        Dim intStart As Integer
        Dim filereader As IO.StreamReader
        strStatFile = INI_Settings.sCampaign & "\stationary.dcg"
        If Dir(strStatFile) = "" Then
            bolerror = True
            strerror = "Cannot find stationary file!"
            Exit Sub
        End If
        If My.Computer.FileSystem.FileExists(strStatFile) Then
            filereader = My.Computer.FileSystem.OpenTextFileReader(strStatFile)
            Do Until filereader.EndOfStream
                strInput = filereader.ReadLine
                intStart = InStr(strInput, "_Static")
                If intStart > 0 Then
                    ReDim Preserve Stat(Stat.Length)
                    intStart = InStr(1, strInput, "X")
                    If intStart > 0 Then
                        Stat(Stat.Length - 1).Active = False
                    Else
                        Stat(Stat.Length - 1).Active = True
                    End If
                    intStart = 3
                    intPos = InStr(intStart, strInput, " ")
                    Stat(Stat.Length - 1).Ident = Trim(Mid(strInput, intStart, intPos - intStart))
                    intStart = intPos + 1
                    intPos = InStr(intStart, strInput, " ")
                    Stat(Stat.Length - 1).Unit = Trim(Mid(strInput, intStart, intPos - intStart))
                    intStart = intPos + 1
                    intPos = InStr(intStart, strInput, " ")
                    Stat(Stat.Length - 1).Side = Val(Mid(strInput, intStart, intPos - intStart))
                    intStart = intPos + 1
                    intPos = InStr(intStart, strInput, " ")
                    Stat(Stat.Length - 1).X = Val(Mid(strInput, intStart, intPos - intStart))
                    intStart = intPos + 1
                    intPos = InStr(intStart, strInput, " ")
                    Stat(Stat.Length - 1).Y = Val(Mid(strInput, intStart, intPos - intStart))
                    intStart = intPos + 1
                    intPos = InStr(intStart, strInput, " ")
                    Stat(Stat.Length - 1).Head = Val(Mid(strInput, intStart, intPos - intStart))
                    intStart = intPos + 1
                    intPos = InStr(intStart, strInput, " ")
                    Stat(Stat.Length - 1).Other = Trim(Mid(strInput, intStart))
                    FindWayPoint(Stat(Stat.Length - 1).X, _
                                    Stat(Stat.Length - 1).Y, _
                                    Stat(Stat.Length - 1).Loc, _
                                    Stat(Stat.Length - 1).intLoc, _
                                    Locat)

                End If
            Loop
            filereader.Close()
        End If
    End Sub
    Public Sub LoadColumnFile(ByRef bolerror As Boolean, _
                            ByRef strerror As String, _
                            ByRef BornPlace() As BornPlaceClass, _
                            ByRef ConvoyInfo() As Convoy, _
                            ByRef Col() As Column, _
                            ByRef Ship() As Column, _
                            ByRef Train() As Column, _
                            ByRef Infantry() As Column, _
                            ByRef Locat() As Location, _
                            ByRef Station() As Location, _
                            ByRef Harbor() As Location, _
                            ByRef INI_Settings As INI_Class)

        Dim strColFile As String
        Dim strInput As String
        Dim intStart As Integer
        Dim filereader As IO.StreamReader
        'This sub loads the columns.dcg file ito the column array
        strColFile = INI_Settings.sCampaign & "\columns.dcg"
        If Dir(strColFile) = "" Then
            bolerror = True
            strerror = "Cannot find column file!"
            Exit Sub
        End If
        If My.Computer.FileSystem.FileExists(strColFile) Then
            filereader = My.Computer.FileSystem.OpenTextFileReader(strColFile)
            Do Until filereader.EndOfStream
                strInput = filereader.ReadLine
                intStart = InStr(strInput, "_Chief")
                If intStart > 0 Then
                    If InStr(strInput, "Trains.") > 0 Then LoadChiefTrain(strInput, _
                                                                            ConvoyInfo, _
                                                                            Train, _
                                                                            Station)
                    If InStr(strInput, "Ships.") > 0 Then LoadChiefShip(strInput, _
                                                                            BornPlace, _
                                                                            ConvoyInfo, _
                                                                            Ship, _
                                                                            Harbor, _
                                                                            INI_Settings)
                    If InStr(strInput, "ShipPack.") > 0 Then LoadChiefShip(strInput, _
                                                                            BornPlace, _
                                                                            ConvoyInfo, _
                                                                            Ship, _
                                                                            Harbor, _
                                                                            INI_Settings)
                    If InStr(strInput, "Vehicles.") > 0 Then LoadChiefColumn(strInput, _
                                                                                ConvoyInfo, _
                                                                                 Col, _
                                                                                 Locat)
                    If InStr(strInput, "Armor.") > 0 Then LoadChiefColumn(strInput, _
                                                                                ConvoyInfo, _
                                                                                Col, _
                                                                                Locat)
                    If InStr(strInput, "Infantry.") > 0 Then LoadInfantryColumn(strInput, _
                                                                                Infantry, _
                                                                                Locat)
                End If
            Loop
            filereader.Close()
        End If
    End Sub
    Public Sub LoadRDSFile(ByRef bolerror As Boolean, _
                            ByRef strerror As String, _
                            ByRef camsettings As Campaign, _
                            ByRef Locat() As Location, _
                            ByRef Road() As Waypoint, _
                            ByRef ShipRoute() As Waypoint, _
                            ByRef RoadWp() As String, _
                            ByRef ini_settings As INI_Class)

        Dim strRDSFile As String
        Dim strInput As String
        Dim strValue As String
        Dim intPos As Integer
        Dim intStart As Integer
        Dim iFrom As Integer
        Dim iTo As Integer
        Dim CurrRoute(0) As Waypoint
        Dim intRoute As Integer
        Dim i As Integer
        Dim filereader As StreamReader
        strRDSFile = ini_settings.sData & camsettings.RouteName & ".rds"
        If Dir(strRDSFile) = "" Then
            bolerror = True
            strerror = "Cannot find RDS file!"
            Exit Sub
        End If
        ReDim Preserve Locat(0)
        ReDim RoadWp(0)
        Locat(0).Loc = "Blank"
        If My.Computer.FileSystem.FileExists(strRDSFile) Then
            filereader = My.Computer.FileSystem.OpenTextFileReader(strRDSFile)
            Do Until filereader.EndOfStream
                strInput = filereader.ReadLine
                intStart = InStr(strInput, "[")
                If intStart > 0 Then
                    'find start location
                    If Road.Length > 1 Then FindLocations(CurrRoute, _
                                        intRoute, _
                                        iFrom, _
                                        iTo, _
                                        Locat, _
                                        Road, _
                                        ini_settings)
                    intRoute = 0
                    ReDim CurrRoute(intRoute)
                    intStart = intStart + 1
                    intPos = InStr(strInput, " to ")
                    strValue = Trim(Mid(strInput, intStart, intPos - intStart))
                    FindLoc(strValue, iFrom, _
                            Locat.Length - 1, _
                            Locat)
                    If iFrom < 1 Then
                        ReDim Preserve Locat(Locat.Length)
                        Locat(Locat.Length - 1).Loc = strValue
                        Locat(Locat.Length - 1).Type = 1
                        Locat(Locat.Length - 1).MaxFuel = ini_settings.intMinFuel
                        Locat(Locat.Length - 1).MaxSup = ini_settings.intMinSup
                        iFrom = Locat.Length - 1
                    End If
                    intStart = intPos + 4
                    intPos = InStr(strInput, "]")
                    strValue = Trim(Mid(strInput, intStart, intPos - intStart))
                    FindLoc(strValue, iTo, _
                            Locat.Length - 1, _
                            Locat)
                    If iTo < 1 Then
                        ReDim Preserve Locat(Locat.Length)
                        Locat(Locat.Length - 1).Loc = strValue
                        Locat(Locat.Length - 1).Type = 1
                        iTo = Locat.Length - 1
                    End If
                    ReDim Preserve Road(Road.Length)
                    With Road(Road.Length - 1)
                        .strFrom = Locat(iFrom).Loc
                        .iFrom = iFrom
                        .strTo = Locat(iTo).Loc
                        .iTo = iTo
                        .Start = RoadWp.Length
                        .iEnd = RoadWp.Length
                        .FrmSpn = .Start + 4
                        .ToSpn = .iEnd - 4
                        Locat(iFrom).RedRoad = Road.Length - 1
                        Locat(iFrom).RedWp = .Start + 5
                        Locat(iTo).BlueRoad = Road.Length - 1
                    End With

                Else
                    If Len(Trim(strInput)) > 0 Then
                        ReDim Preserve RoadWp(RoadWp.Length)
                        i = InStr(strInput, " 0 ")
                        If i > 0 Then
                            RoadWp(RoadWp.Length - 1) = Trim(Left(strInput, i))
                        Else
                            RoadWp(RoadWp.Length - 1) = Trim(strInput)
                        End If
                        Road(Road.Length - 1).iEnd = RoadWp.Length - 1
                        Road(Road.Length - 1).ToSpn = Road(Road.Length - 1).iEnd - 4
                        Road(Road.Length - 1).ToStp = Road(Road.Length - 1).iEnd - 6
                        Locat(Road(Road.Length - 1).iTo).BlueWP = Road(Road.Length - 1).iEnd - 5
                        intRoute = intRoute + 1
                        ReDim Preserve CurrRoute(intRoute)
                        FindCoor(strInput, _
                                CurrRoute(intRoute).AlliedX, _
                                CurrRoute(intRoute).AlliedY, _
                                CurrRoute(intRoute).AlliedH)
                    End If
                End If
            Loop
            filereader.Close()
            FindLocations(CurrRoute, _
                                intRoute, _
                                iFrom, _
                                iTo, _
                                Locat, _
                                Road, _
                                ini_settings)
        End If
        Exit Sub

    End Sub
    Public Sub FindHead(ByRef X1 As Double, _
                        ByRef Y1 As Double, _
                        ByRef X2 As Double, _
                        ByRef Y2 As Double, _
                        ByRef Head As Integer)
        Dim dbX As Double
        Dim dbY As Double
        Dim dbDist As Double
        Dim dbRatio As Double
        dbX = X2 - X1
        dbY = Y2 - Y1
        dbDist = Math.Sqrt((dbX ^ 2) + (dbY ^ 2))
        If dbY = 0 Then
            Head = 90
        Else
            dbRatio = Math.Abs(dbX / dbY)
            Head = Int(Math.Atan(dbRatio) * 180 / 3.14)
        End If
        If dbX >= 0 Then
            If dbY < 0 Then Head = 180 - Head
        Else
            If dbY < 0 Then
                Head = 180 + Head
            Else
                Head = 360 - Head
            End If
        End If
    End Sub

    Public Sub FindLoc(ByRef strLoc As String, _
                        ByRef intLoc As Integer, _
                        ByRef iTot As Integer, _
                        ByRef Locat() As Location)
        If iTot < 1 Then
            intLoc = iTot
            Exit Sub
        End If
        For intLoc = iTot To 0 Step -1
            If Locat(intLoc).Loc = strLoc Then
                Exit For
            End If
        Next
    End Sub
    Public Sub FindCoor(ByRef strCoor As String, _
                        ByRef dblX As Double, _
                        ByRef dblY As Double, _
                        ByRef iH As Integer)
        Dim intStart As Integer
        Dim intPos As Integer

        If strCoor = "" Then Exit Sub
        If InStr(strCoor, "[") > 0 Then Exit Sub
        strCoor = Trim(strCoor)
        intStart = 1
        intPos = InStr(strCoor, " ")
        dblX = Val(Mid(strCoor, intStart, intPos - intStart))
        intStart = intPos + 1
        intPos = InStr(intStart, strCoor, " ")
        If intPos > 0 Then
            dblY = Val(Mid(strCoor, intStart, intPos - intStart))
            iH = Int(Val(Mid(strCoor, intPos + 1)))
        Else
            dblY = Val(Mid(strCoor, intStart))
            iH = 0
        End If
    End Sub

    Public Sub LoadRLSFile(ByRef bolerror As Boolean, _
                            ByRef strerror As String, _
                            ByRef camsettings As Campaign, _
                            ByRef Station() As Location, _
                            ByRef Rail() As Waypoint, _
                            ByRef RailWP() As String, _
                            ByRef INI_Settings As INI_Class)

        Dim strRLSFile As String
        Dim strInput As String
        Dim strValue As String
        Dim intPos As Integer
        Dim intStart As Integer
        Dim iFrom As Integer
        Dim iTo As Integer
        Dim intRoute As Integer
        Dim CurrRoute(0) As Waypoint
        Dim i As Integer
        Dim filereader As IO.StreamReader
        strRLSFile = INI_Settings.sData & camsettings.RouteName & ".rls"
        If Dir(strRLSFile) = "" Then
            Exit Sub
        End If
        ReDim RailWP(0)
        If My.Computer.FileSystem.FileExists(strRLSFile) Then
            filereader = My.Computer.FileSystem.OpenTextFileReader(strRLSFile)
            Do Until filereader.EndOfStream
                strInput = filereader.ReadLine

                intStart = InStr(strInput, "[")
                If intStart > 0 Then
                    'find start stationion
                    If Rail.Length > 1 Then FindStations(CurrRoute, _
                                            intRoute, _
                                            iFrom, _
                                            iTo, _
                                            Station, _
                                            Rail)
                    intRoute = 0
                    intStart = intStart + 1
                    intPos = InStr(strInput, " to ")
                    strValue = Trim(Mid(strInput, intStart, intPos - intStart))
                    FindStation(strValue, iFrom, _
                                Station.Length - 1, _
                                Station)
                    If iFrom < 1 Then
                        ReDim Preserve Station(Station.Length)
                        Station(Station.Length - 1).Loc = strValue
                        Station(Station.Length - 1).Type = 2
                        iFrom = Station.Length - 1
                    End If

                    intStart = intPos + 4
                    intPos = InStr(strInput, "]")
                    strValue = Trim(Mid(strInput, intStart, intPos - intStart))
                    FindStation(strValue, iTo, _
                                Station.Length - 1, _
                                Station)
                    If iTo < 1 Then
                        ReDim Preserve Station(Station.Length)
                        Station(Station.Length - 1).Loc = strValue
                        Station(Station.Length - 1).Type = 2
                        iTo = Station.Length - 1
                    End If
                    ReDim Preserve Rail(Rail.Length)
                    With Rail(Rail.Length - 1)
                        .strFrom = Station(iFrom).Loc
                        .iFrom = iFrom
                        .strTo = Station(iTo).Loc
                        .iTo = iTo
                        .Start = RailWP.Length
                        .iEnd = RailWP.Length
                        .FrmSpn = .Start + 4
                        .FrmStp = .Start + 6
                        .ToSpn = .iEnd - 4
                        .ToStp = .iEnd - 6
                    End With

                Else
                    If Len(Trim(strInput)) > 0 Then
                        ReDim Preserve RailWP(RailWP.Length)
                        i = InStr(strInput, " 0 ")
                        If i > 0 Then
                            RailWP(RailWP.Length - 1) = Trim(Left(strInput, i))
                        Else
                            RailWP(RailWP.Length - 1) = Trim(strInput)
                        End If
                        Rail(Rail.Length - 1).iEnd = RailWP.Length - 1
                        Rail(Rail.Length - 1).ToSpn = Rail(Rail.Length - 1).iEnd - 4
                        Rail(Rail.Length - 1).ToStp = Rail(Rail.Length - 1).iEnd - 6
                        intRoute = intRoute + 1
                        ReDim Preserve CurrRoute(intRoute)
                        FindCoor(strInput, _
                            CurrRoute(intRoute).AlliedX, _
                            CurrRoute(intRoute).AlliedY, _
                            CurrRoute(intRoute).AlliedH)
                    End If
                End If
            Loop
            filereader.Close()
            FindStations(CurrRoute, _
                                intRoute, _
                                iFrom, _
                                iTo, _
                                Station, _
                                Rail)
        End If

    End Sub

    Public Sub LoadSRDFile(ByRef bolerror As Boolean, _
                            ByRef strerror As String, _
                            ByRef camsettings As Campaign, _
                            ByRef Harbor() As Location, _
                            ByRef ShipRoute() As Waypoint, _
                            ByRef SeaWP() As WP, _
                            ByRef ini_settings As INI_Class)


        Dim strSRDFile As String
        Dim strInput As String
        Dim strValue As String
        Dim intPos As Integer
        Dim intStart As Integer
        Dim iFrom As Integer
        Dim iTo As Integer
        Dim intRoute As Integer
        Dim CurrRoute(0) As Waypoint
        Dim i As Integer
        Dim filereader As IO.StreamReader
        strSRDFile = ini_settings.sData & camsettings.RouteName & ".SRD"
        If Dir(strSRDFile) = "" Then
            Exit Sub
        End If
        ReDim SeaWP(0)
        If My.Computer.FileSystem.FileExists(strSRDFile) Then
            filereader = My.Computer.FileSystem.OpenTextFileReader(strSRDFile)
            Do Until filereader.EndOfStream


                strInput = filereader.ReadLine

                intStart = InStr(strInput, "[")
                If intStart > 0 Then
                    'find start harbor
                    If ShipRoute.Length > 1 Then FindHarbors(CurrRoute, _
                                            intRoute, _
                                            iFrom, _
                                            iTo, _
                                            Harbor, _
                                            ShipRoute, _
                                            ini_settings)
                    intRoute = 0
                    intStart = intStart + 1
                    intPos = InStr(strInput, " to ")
                    strValue = Trim(Mid(strInput, intStart, intPos - intStart))
                    FindHarbor(strValue, _
                               iFrom, Harbor.Length - 1, _
                               Harbor)
                    If iFrom < 1 Then
                        ReDim Preserve Harbor(Harbor.Length)
                        Harbor(Harbor.Length - 1).Loc = strValue
                        Harbor(Harbor.Length - 1).Type = 3
                        iFrom = Harbor.Length - 1
                    End If

                    intStart = intPos + 4
                    intPos = InStr(strInput, "]")
                    strValue = Trim(Mid(strInput, intStart, intPos - intStart))
                    FindHarbor(strValue, _
                               iTo, _
                               Harbor.Length - 1, _
                               Harbor)
                    If iTo < 1 Then
                        ReDim Preserve Harbor(Harbor.Length)
                        Harbor(Harbor.Length - 1).Loc = strValue
                        Harbor(Harbor.Length - 1).Type = 3
                        iTo = Harbor.Length - 1
                    End If


                    ReDim Preserve ShipRoute(ShipRoute.Length)
                    With ShipRoute(ShipRoute.Length - 1)
                        .strFrom = Harbor(iFrom).Loc
                        .iFrom = iFrom
                        .strTo = Harbor(iTo).Loc
                        .iTo = iTo
                        .Start = SeaWP.Length
                        .iEnd = SeaWP.Length
                        .FrmSpn = .Start + 4
                        .ToSpn = .iEnd - 4
                    End With

                Else
                    If Len(Trim(strInput)) > 0 Then
                        ReDim Preserve SeaWP(SeaWP.Length)
                        i = InStr(strInput, " 0 ")

                        FindCoor(strInput, _
                            SeaWP(SeaWP.Length - 1).X, _
                            SeaWP(SeaWP.Length - 1).Y, _
                            SeaWP(SeaWP.Length - 1).H)
                        ShipRoute(ShipRoute.Length - 1).iEnd = SeaWP.Length - 1
                        ShipRoute(ShipRoute.Length - 1).ToSpn = ShipRoute(ShipRoute.Length - 1).iEnd - 4
                        ShipRoute(ShipRoute.Length - 1).ToStp = ShipRoute(ShipRoute.Length - 1).iEnd - 4
                        intRoute = intRoute + 1
                        ReDim Preserve CurrRoute(intRoute)
                        FindCoor(strInput, _
                            CurrRoute(intRoute).AlliedX, _
                            CurrRoute(intRoute).AlliedY, _
                            CurrRoute(intRoute).AlliedH)
                    End If
                End If
            Loop
            filereader.Close()
            FindHarbors(CurrRoute, _
                            intRoute, _
                            iFrom, _
                            iTo, _
                            Harbor, _
                            ShipRoute, _
                            ini_settings)
        End If

    End Sub
    Public Sub LoadTerritoryFile(ByRef bolerror As Boolean, _
                            ByRef strerror As String, _
                            ByRef MissSettings As Mission, _
                            ByRef Locat() As Location, _
                            ByRef Station() As Location, _
                            ByRef Harbor() As Location, _
                            ByRef INI_Settings As INI_Class)


        Dim strInput As String
        Dim intPos As Integer
        Dim Terr As Location
        Dim intStart As Integer
        Dim strTerrFile As String
        Dim intLoc As Integer
        Dim filereader As IO.StreamReader
        strTerrFile = INI_Settings.sCampaign & "\territory.dcg"
        If My.Computer.FileSystem.FileExists(strTerrFile) Then
            filereader = My.Computer.FileSystem.OpenTextFileReader(strTerrFile)
            Do Until filereader.EndOfStream
                strInput = filereader.ReadLine
                Terr.Loc = ""
                If strInput <> "" Then
                    strInput = Trim(strInput)
                    intStart = 1
                    intPos = InStr(intStart, strInput, " ")
                    If intPos > 0 Then
                        Terr.Loc = Mid(strInput, intStart, intPos - intStart)
                        intStart = intPos + 1
                        intPos = InStr(intStart, strInput, " ")
                        Terr.Side = Val(Mid(strInput, intStart, intPos - intStart))
                    End If

                    intStart = InStr(strInput, "supply=")
                    If intStart > 0 Then
                        intPos = InStr(intStart, strInput, " ")
                        intStart = intStart + 7
                        Terr.Supply = Int(Val(Mid(strInput, intStart)))
                    Else
                        Terr.Supply = 0
                    End If
                    intStart = InStr(strInput, "fuel=")
                    If intStart > 0 Then
                        intPos = InStr(intStart, strInput, " ")
                        intStart = intStart + 5
                        Terr.Fuel = Int(Val(Mid(strInput, intStart)))
                    Else
                        Terr.Fuel = 0
                    End If
                    intStart = InStr(strInput, "suppressed=")
                    If intStart > 0 Then

                        intStart = intStart + 11
                        Terr.Suppressed = Int(Val(Mid(strInput, intStart)))
                    Else
                        Terr.Suppressed = 0
                    End If
                    intStart = InStr(strInput, "fuellimit=")
                    If intStart > 0 Then

                        intStart = intStart + 10
                        Terr.FuelLimit = Int(Val(Mid(strInput, intStart)))
                    Else
                        Terr.FuelLimit = MissSettings.MaxFuel
                    End If
                    intStart = InStr(strInput, "points=")
                    If intStart > 0 Then

                        intStart = intStart + 7
                        Terr.Points = Int(Val(Mid(strInput, intStart)))
                    Else
                        Terr.Points = 0
                    End If
                    For intLoc = 1 To Locat.Length - 1
                        If Terr.Loc = Locat(intLoc).Loc Then
                            Locat(intLoc).Allied = 0
                            Locat(intLoc).Axis = 0
                            Locat(intLoc).Side = Terr.Side
                            Locat(intLoc).Supply = Terr.Supply
                            Locat(intLoc).Fuel = Terr.Fuel
                            Locat(intLoc).Suppressed = Terr.Suppressed
                            Locat(intLoc).FuelLimit = Terr.FuelLimit
                            Locat(intLoc).Points = Terr.Points
                            If Locat(intLoc).MaxFuel < INI_Settings.intMinFuel Then Locat(intLoc).MaxFuel = INI_Settings.intMinFuel
                            If Locat(intLoc).MaxSup < INI_Settings.intMinSup Then Locat(intLoc).MaxSup = INI_Settings.intMinSup
                            Exit For
                        End If
                    Next
                    For intLoc = 1 To Station.Length - 1
                        If Terr.Loc = Station(intLoc).Loc Then
                            Station(intLoc).Allied = 0
                            Station(intLoc).Axis = 0
                            Station(intLoc).Side = Terr.Side
                            Station(intLoc).Supply = Terr.Supply
                            Station(intLoc).Fuel = Terr.Fuel
                            Station(intLoc).Suppressed = Terr.Suppressed
                            Station(intLoc).FuelLimit = Terr.FuelLimit
                            Station(intLoc).Points = Terr.Points
                            Exit For
                        End If
                    Next
                    For intLoc = 1 To Harbor.Length - 1
                        If Terr.Loc = Harbor(intLoc).Loc Then
                            Harbor(intLoc).Allied = 0
                            Harbor(intLoc).Axis = 0
                            Harbor(intLoc).Side = Terr.Side
                            Harbor(intLoc).Supply = Terr.Supply
                            Harbor(intLoc).Fuel = Terr.Fuel
                            Harbor(intLoc).Suppressed = Terr.Suppressed
                            Harbor(intLoc).FuelLimit = Terr.FuelLimit
                            Harbor(intLoc).Points = Terr.Points
                            Exit For
                        End If
                    Next
                End If
            Loop
            filereader.Close()
        End If
    End Sub
    Public Sub LoadConvoyFile(ByRef bolerror As Boolean, _
                            ByRef strerror As String, _
                            ByRef ConvoyVeh(,) As String, _
                            ByRef ConvoyMov(,) As String, _
                            ByRef ConvoyInfo() As Convoy, _
                            ByRef ini_settings As INI_Class)

        Dim strConFile As String
        Dim strInput As String
        Dim strValue As String
        Dim intPos As Integer
        Dim intStart As Integer
        Dim intVeh As Integer
        Dim filereader As IO.StreamReader
        strConFile = ini_settings.sData & "convoy.dcg"
        If Dir(strConFile) = "" Then
            bolerror = True
            strerror = "Cannot find convoy file!"
            Exit Sub
        End If
        If My.Computer.FileSystem.FileExists(strConFile) Then
            filereader = My.Computer.FileSystem.OpenTextFileReader(strConFile)
            Do Until filereader.EndOfStream
                strInput = filereader.ReadLine
                intStart = InStr(strInput, "[")
                intPos = InStr(strInput, "]")
                If intStart > 0 And intPos > 0 And intPos > intStart Then
                    intStart = intStart + 1
                    strValue = Trim(Mid(strInput, intStart, intPos - intStart))
                    ReDim Preserve ConvoyInfo(ConvoyInfo.Length)
                    ReDim Preserve ConvoyVeh(20, ConvoyInfo.Length - 1)
                    ReDim Preserve ConvoyMov(20, ConvoyInfo.Length - 1)
                    ConvoyInfo(ConvoyInfo.Length - 1).Unit = strValue
                    intVeh = 0
                Else
                    If ConvoyInfo.Length > 1 Then
                        intStart = InStr(strInput, "Fuel=")
                        If intStart > 0 Then
                            intPos = InStr(strInput, "=") + 1
                            ConvoyInfo(ConvoyInfo.Length - 1).Fuel = Val(Mid(strInput, intPos))
                        End If
                        intStart = InStr(strInput, "Supply=")
                        If intStart > 0 Then
                            intPos = InStr(strInput, "=") + 1
                            ConvoyInfo(ConvoyInfo.Length - 1).Supply = Val(Mid(strInput, intPos))
                        End If
                        intStart = InStr(strInput, "Troops=")
                        If intStart > 0 Then
                            intPos = InStr(strInput, "=") + 1
                            ConvoyInfo(ConvoyInfo.Length - 1).Troops = Val(Mid(strInput, intPos))
                        End If
                        intStart = InStr(strInput, "Artillery=")
                        If intStart > 0 Then
                            intPos = InStr(strInput, "=") + 1
                            ConvoyInfo(ConvoyInfo.Length - 1).Artillery = Val(Mid(strInput, intPos))
                        End If
                        intStart = InStr(strInput, "Convoys=")
                        If intStart > 0 Then
                            intPos = InStr(strInput, "=") + 1
                            ConvoyInfo(ConvoyInfo.Length - 1).Columns = Val(Mid(strInput, intPos))
                        End If

                        intStart = InStr(strInput, "Amp=")
                        If intStart > 0 Then
                            intPos = InStr(strInput, "=") + 1
                            ConvoyInfo(ConvoyInfo.Length - 1).Amp = Val(Mid(strInput, intPos))
                        End If

                        intStart = InStr(strInput, "BR=")
                        If intStart > 0 Then
                            intPos = InStr(strInput, "=") + 1
                            ConvoyInfo(ConvoyInfo.Length - 1).BR = Val(Mid(strInput, intPos))
                        End If

                        intStart = InStr(strInput, "Carrier=")
                        If intStart > 0 Then
                            intPos = InStr(strInput, "=") + 1
                            ConvoyInfo(ConvoyInfo.Length - 1).Carrier = Val(Mid(strInput, intPos))
                        End If

                        intStart = InStr(strInput, "Armor=")
                        If intStart > 0 Then
                            intPos = InStr(strInput, "=") + 1
                            ConvoyInfo(ConvoyInfo.Length - 1).Armor = Val(Mid(strInput, intPos))
                        End If

                        intStart = InStr(strInput, "MultUnits=")
                        If intStart > 0 Then
                            intPos = InStr(strInput, "=") + 1
                            ConvoyInfo(ConvoyInfo.Length - 1).MultUnits = Val(Mid(strInput, intPos))
                        End If

                        intStart = InStr(strInput, "vehicles.")
                        If intStart > 0 Then
                            intVeh = intVeh + 1
                            ConvoyInfo(ConvoyInfo.Length - 1).Size = intVeh
                            intStart = InStr(strInput, " ")
                            If intStart > 0 Then
                                ConvoyVeh(intVeh, ConvoyInfo.Length - 1) = Trim(Left(strInput, intStart))
                                ConvoyMov(intVeh, ConvoyInfo.Length - 1) = Trim(Mid(strInput, intStart))
                            Else
                                ConvoyVeh(intVeh, ConvoyInfo.Length - 1) = Trim(strInput)
                            End If
                        End If
                        intStart = InStr(strInput, "ships.")
                        If intStart > 0 Then
                            intVeh = intVeh + 1
                            ConvoyInfo(ConvoyInfo.Length - 1).Size = intVeh
                            ConvoyVeh(intVeh, ConvoyInfo.Length - 1) = Trim(strInput)
                        End If
                    End If
                End If
            Loop
            filereader.Close()
        End If
    End Sub
    Public Sub FindWayPoint(ByRef dblX As Double, _
                            ByRef dblY As Double, _
                            ByRef strLoc As String, _
                            ByRef intLoc As Integer, _
                            ByRef Locat() As Location)

        Dim dblDistance As Double
        Dim dblTemp As Double
        Dim intCount As Integer
        dblDistance = Math.Sqrt((dblX ^ 2) + (dblY ^ 2))
        For intCount = 1 To Locat.Length - 1
            dblTemp = Math.Sqrt(((Locat(intCount).X - dblX) ^ 2) + ((Locat(intCount).Y - dblY) ^ 2))
            If dblDistance > dblTemp Then
                dblDistance = dblTemp
                strLoc = Locat(intCount).Loc
                intLoc = intCount
            End If
        Next
    End Sub
    Public Sub FindWPRange(ByRef dblX As Double, _
                            ByRef dblY As Double, _
                            ByRef strLoc As String, _
                            ByRef intLoc As Integer, _
                            ByRef iRange As Integer, _
                            ByRef Locat() As Location)

        Dim dblDistance As Double
        Dim dblTemp As Double
        Dim intCount As Integer
        strLoc = ""
        intLoc = 0
        dblDistance = iRange * 10 ^ 3
        For intCount = Locat.Length - 1 To 1 Step -1
            dblTemp = Math.Sqrt(((Locat(intCount).X - dblX) ^ 2) + ((Locat(intCount).Y - dblY) ^ 2))
            If dblDistance > dblTemp Then
                dblDistance = dblTemp
                strLoc = Locat(intCount).Loc
                intLoc = intCount
                Exit For
            End If
        Next
    End Sub
    Public Sub ProcessEvents(ByRef bolerror As Boolean, _
                                ByRef strerror As String, _
                                ByRef sEventDate As String, _
                                ByRef Bridge() As Brid, _
                                ByRef Fact() As Factory, _
                                ByRef Rocket() As RocketType, _
                                ByRef camsettings As Campaign, _
                                ByRef MissSettings As Mission, _
                                ByRef Stat() As Stationary, _
                                ByRef Col() As Column, _
                                ByRef Ship() As Column, _
                                ByRef Train() As Column, _
                                ByRef Infantry() As Column, _
                                ByRef Locat() As Location, _
                                ByRef Station() As Location, _
                                ByRef strDebrief() As String, _
                                ByRef ProcEvent As Integer, _
                                ByRef ActiveBridge() As String, _
                                ByRef Radar() As Factory, _
                                ByRef ini_settings As INI_Class, _
                                ByRef Manufacture() As Factory)
        Dim strEventFile As String
        Dim strInput As String
        Dim strID As String
        Dim strUnit As String
        Dim intPos As Integer
        Dim intStart As Integer
        Dim intID As Integer
        Dim strOutput As String
        Dim iBridge As Integer
        Dim sBridge As String
        Dim iRepair As Integer
        Dim filereader As IO.StreamReader
        Dim sDamage As Single
        'This sub removes destroyed items from the static and column arrays
        strEventFile = ini_settings.sServer & "\eventlog.dcg"

        If My.Computer.FileSystem.FileExists(strEventFile) Then
            filereader = My.Computer.FileSystem.OpenTextFileReader(strEventFile)
            Do Until filereader.EndOfStream

                strInput = filereader.ReadLine
                intStart = InStr(strInput, " Mission: ")
                If intStart > 0 Then 'Find Mission Date
                    intStart = InStr(strInput, "[")
                    intPos = InStr(strInput, "]") + 1
                    If intPos > intStart Then
                        sEventDate = Trim(Mid(strInput, intStart, intPos))
                        If sEventDate = ini_settings.sINIDate Then
                            ProcEvent = 0
                            Exit Do
                        Else
                            ini_settings.sINIDate = sEventDate
                            ProcEvent = 1
                        End If
                    End If
                End If
                If strInput.Contains("ExplosiveDamage") Then 'Factory Plate Explosion
                    Dim sArray() As String
                    sArray = strInput.Split(" ")
                    sDamage = 0
                    strID = ""
                    intID = 0
                    For i = 0 To sArray.Length - 1
                        If i = 3 Then strID = sArray(i)
                        If i = 5 Then sDamage = Val(sArray(i))
                    Next
                    If strID.Length > 0 And Manufacture.Length > 1 Then
                        For intID = Manufacture.Length - 1 To 1 Step -1
                            If strID = Manufacture(intID).ID Then Exit For
                        Next
                    End If
                    If intID > 0 Then
                        With Manufacture(intID)
                            .Manufacture -= sDamage * ini_settings.sExplosion
                            ReDim Preserve strDebrief(strDebrief.Length)
                            strDebrief(strDebrief.Length - 1) = "Factory Plate bombed at " & _
                                                                    .Loc & " " & _
                                                                    Format(sDamage / ini_settings.sExplosion, "0.0000")
                        End With
                    End If
                End If
                intStart = InStr(strInput, " destroyed by ")
                If intStart > 0 Then
                    strID = ""
                    FindIDinBY(strInput, strID)
                    intStart = InStr(strID, "_Static")
                    If intStart > 0 Then
                        FindStatic(strID, _
                                   intID, _
                                   Stat)
                        If intID > 1 Then
                            intStart = InStr(Stat(intID).Unit, "$") + 1
                            strUnit = Mid(Stat(intID).Unit, intStart)
                            strOutput = ""
                            FindGrid(Locat(Stat(intID).intLoc).X, Locat(Stat(intID).intLoc).Y, strOutput)
                            ReDim Preserve strDebrief(strDebrief.Length)
                            strDebrief(strDebrief.Length - 1) = strUnit & " at " & Stat(intID).Loc & strOutput
                            Stat(intID).Active = False
                        End If
                    End If


                    intStart = InStr(strID, "_Rocket")
                    If intStart > 0 Then
                        intPos = intStart + 6
                        strID = Trim(Left(strID, intPos))
                        FindRocket(strID, _
                                   intID, _
                                   Rocket)
                        If intID > 0 Then
                            With Rocket(intID)
                                If .Active Then
                                    .Curr = .Curr - 1
                                    If .Curr < 0 Then .Curr = 0
                                End If
                            End With
                        End If
                    End If

                    intStart = InStr(strID, "_Chief")
                    If intStart > 0 Then
                        intPos = intStart + 5
                        strID = Trim(Left(strID, intPos))
                        'Check columns array
                        FindColumn(strID, _
                                   intID, _
                                   Col)
                        If intID > 0 Then
                            With Col(intID)
                                If .iFrom > 0 Or InStr(.iFrom, "_Chief") > 0 Then
                                    .Curr = .Curr - 1
                                    If .Curr < 0 Then .Curr = 0
                                End If
                            End With
                        End If
                        'Check infantry array
                        FindInfantry(strID, _
                                     intID, _
                                     Infantry)
                        If intID > 0 Then
                            With Infantry(intID)
                                If .iFrom > 0 Or InStr(.sFrom, "_Chief") > 0 Then
                                    .Curr = .Curr - 1
                                    If .Curr < 0 Then .Curr = 0
                                End If
                            End With
                        End If
                        'Check Ship Array
                        FindShip(strID, _
                                 intID, _
                                 Ship)
                        If intID > 0 Then
                            With Ship(intID)
                                If .iFrom > 0 Then

                                    .Curr = .Curr - 1
                                    If .Curr < 0 Then .Curr = 0
                                End If
                            End With
                        End If
                        'Check Train Array
                        FindTrain(strID, _
                                    intID, _
                                    Train)
                        If intID > 0 Then
                            With Train(intID)
                                If .iFrom > 0 Then

                                    .Curr = .Curr - 1
                                    If .Curr < 0 Then .Curr = 0
                                End If
                            End With
                        End If

                    End If
                    'Factory Destroyed
                    intStart = InStr(strID, "_fact")
                    If intStart > 0 Then
                        intPos = intStart + 4
                        strID = Trim(Left(strID, intPos))
                        Findfact(strID, _
                                 intID, _
                                 Fact)
                        If intID > 0 Then
                            With Fact(intID)
                                If .Active Then
                                    .Curr = .Curr - 1
                                    If .Curr / .Size < 0.5 Then
                                        .Active = False
                                        If .Col > 0 Then iRepair = -1
                                        Locat(.intLoc).Fuel = Locat(.intLoc).Fuel - .Fuel
                                        Locat(.intLoc).Supply = Locat(.intLoc).Supply - .Supply
                                        If Locat(.intLoc).Fuel < 1 Then Locat(.intLoc).Fuel = 0
                                        If Locat(.intLoc).Supply < 1 Then Locat(.intLoc).Supply = 0
                                        strOutput = ""
                                        FindGrid(Locat(.intLoc).X, Locat(.intLoc).Y, strOutput)
                                        ReDim Preserve strDebrief(strDebrief.Length)
                                        strDebrief(strDebrief.Length - 1) = .Unit & " at " & .Loc & " " & strOutput
                                    End If
                                End If
                            End With
                        End If
                    End If
                    'Radar Destroyed
                    If intStart > 0 Then
                        intPos = intStart + 4
                        strID = Trim(Left(strID, intPos))
                        FindRadar(strID, _
                                  intID, _
                                  Radar)
                        If intID > 0 Then
                            With Radar(intID)
                                If .Active Then
                                    .Curr = .Curr - 1
                                    If .Curr / .Size < 0.5 Then
                                        .Active = False
                                        If .Side = 1 Then
                                            Locat(.intLoc).Allied = Locat(.intLoc).Allied - .Troops
                                            If Locat(.intLoc).Allied < 0 Then Locat(.intLoc).Allied = 0
                                        End If
                                        If .Side = 2 Then
                                            Locat(.intLoc).Axis = Locat(.intLoc).Axis - .Troops
                                            If Locat(.intLoc).Axis < 0 Then Locat(.intLoc).Axis = 0
                                        End If
                                        strOutput = ""
                                        FindGrid(Locat(.intLoc).X, Locat(.intLoc).Y, strOutput)
                                        ReDim Preserve strDebrief(strDebrief.Length)
                                        strDebrief(strDebrief.Length - 1) = .Unit & " at " & .Loc & " " & strOutput
                                    End If
                                End If
                            End With
                        End If
                    End If


                    'BRIDGES
                    intStart = InStr(strID, "Bridge")
                    If intStart > 0 Then
                        If MissSettings.Bridge > 0 Then
                            LocateBridge(strInput, _
                                         strID, _
                                         Bridge, _
                                         camsettings, _
                                         MissSettings, _
                                         Locat, _
                                         ini_settings)
                            LocateRailBridge(strInput, _
                                             strID, _
                                             Bridge, _
                                             camsettings, _
                                            MissSettings, _
                                            Station, _
                                            ini_settings)
                        Else
                            'Check for Bridges in Active Bridge File
                            If ActiveBridge.Length > 1 Then
                                sBridge = strID
                                For iBridge = 1 To ActiveBridge.Length - 1
                                    If sBridge = ActiveBridge(iBridge) Then
                                        LocateBridge(strInput, _
                                                     strID, _
                                                     Bridge, _
                                                     camsettings, _
                                                     MissSettings, _
                                                     Locat, _
                                                     ini_settings)
                                        LocateRailBridge(strInput, _
                                                         strID, _
                                                         Bridge, _
                                                         camsettings, _
                                                         MissSettings, _
                                                         Station, _
                                                         ini_settings)
                                        Exit For
                                    End If
                                Next
                            End If
                        End If
                    End If
                End If

            Loop
            filereader.Close()
        Else
            ini_settings.sINIDate = ""
            ReDim Preserve strDebrief(strDebrief.Length)
            strDebrief(strDebrief.Length - 1) = "Possible error cannot find EVENTLOG FILE !"
        End If
    End Sub

    Public Sub FindIDinBY(ByRef strLine As String, _
                            ByRef strID As String)
        Dim intStart As Integer
        Dim intPos As Integer
        intStart = InStr(strLine, "] ") + 1
        intPos = InStr(strLine, " destroyed by ")
        strID = Trim(Mid(strLine, intStart, intPos - intStart))
    End Sub
    Public Sub FindStatic(ByRef strID As String, _
                            ByRef intStatic As Integer, _
                            ByRef Stat() As Stationary)
        For intStatic = Stat.Length - 1 To 1 Step -1
            If strID = Stat(intStatic).Ident Then
                Exit For
            End If
        Next
    End Sub
    Public Sub FindCon(ByRef strUnit As String, _
                        ByRef intCon As Integer, _
                        ByRef ConvoyInfo() As Convoy)
        For intCon = ConvoyInfo.Length - 1 To 1 Step -1
            If strUnit = ConvoyInfo(intCon).Unit Then
                Exit For
            End If
        Next
    End Sub
    Public Sub FindColumn(ByRef strID As String, _
                            ByRef intChief As Integer, _
                            ByRef Col() As Column)
        If Col.Length > 1 Then
            For intChief = Col.Length - 1 To 1 Step -1
                If strID = Col(intChief).Ident Then
                    Exit For
                End If
            Next
        Else
            intChief = 0
        End If
    End Sub
    Public Sub FindInfantry(ByRef strID As String, _
                                ByRef intChief As Integer, _
                                ByRef Infantry() As Column)
        If Infantry.Length > 1 Then
            For intChief = Infantry.Length - 1 To 1 Step -1
                If strID = Infantry(intChief).Ident Then
                    Exit For
                End If
            Next
        Else
            intChief = 0
        End If
    End Sub
    Public Sub GenDebug(ByRef smainfolder As String, _
                        ByRef sEventDate As String, _
                        ByRef BornPlace() As BornPlaceClass, _
                        ByRef Bridge() As Brid, _
                        ByRef StructInfo() As Building, _
                        ByRef Fact() As Factory, _
                        ByRef Rocket() As RocketType, _
                        ByRef Stat() As Stationary, _
                        ByRef Col() As Column, _
                        ByRef Ship() As Column, _
                        ByRef Train() As Column, _
                        ByRef Infantry() As Column, _
                        ByRef Locat() As Location, _
                        ByRef Station() As Location, _
                        ByRef Harbor() As Location, _
                        ByRef Road() As Waypoint, _
                        ByRef ShipRoute() As Waypoint, _
                        ByRef Rail() As Waypoint, _
                        ByRef strDebrief() As String, _
                        ByRef strFrontLine() As String, _
                        ByRef strACMove() As String, _
                        ByRef GenMiss As Integer, _
                        ByRef ProcEvent As Integer, _
                        ByRef Squad() As Squad_Type, _
                        ByRef Radar() As Factory)
        Dim strDebug As String
        Dim intCount As Integer
        Dim sb As StringBuilder
        strDebug = smainfolder & "\debug.txt"
        For intCount = 0 To 999
            strDebug = smainfolder & "\debug" & Format(intCount, "000") & ".txt"
            If Dir(strDebug) = "" Then Exit For
        Next
        sb = New StringBuilder
        sb.AppendLine("GenMiss=" & Str(GenMiss))
        sb.AppendLine("Process Events=" & Str(ProcEvent))
        sb.AppendLine(sEventDate)
        sb.AppendLine("")
        sb.AppendLine("[Columns]")
        For intCount = 1 To Col.Length - 1
            With Col(intCount)
                sb.AppendLine(Format(intCount, "000 ") & _
                            .Ident & " " & _
                            .Unit & " " & _
                            .Side & " " & _
                            .sFrom & " " & _
                            .iFrom & " " & _
                            .sTo & " " & _
                            .iTo & " " & _
                            .Size & " " & _
                            .Curr & " " & _
                            .Direction & " " & _
                            .Troops & " " & _
                            .Fuel & " " & _
                            .Supply & " " & _
                            .Type)
            End With
        Next

        sb.AppendLine("[Infantry]")
        For intCount = 1 To Infantry.Length - 1
            With Infantry(intCount)
                sb.AppendLine(Format(intCount, "000 ") & _
                            .Ident & " " & _
                            .Unit & " " & _
                            .Side & " " & _
                            .sFrom & " " & _
                            .iFrom & " " & _
                            .sTo & " " & _
                            .iTo & " " & _
                            .Size & " " & _
                            .Curr & " " & _
                            .Direction & " " & _
                            .Troops & " " & _
                            .Fuel & " " & _
                            .Supply & " " & _
                            .Type)
            End With
        Next

        sb.AppendLine("")
        sb.AppendLine("[Ship]")
        For intCount = 1 To Ship.Length - 1
            With Ship(intCount)
                sb.AppendLine(Format(intCount, "000 ") & _
                            .Ident & " " & _
                            .Unit & " " & _
                            .Side & " " & _
                            .sFrom & " " & _
                            .iFrom & " " & _
                            .sTo & " " & _
                            .iTo & " " & _
                            .Size & " " & _
                            .Curr & " " & _
                            .Direction & " " & _
                            .Troops & " " & _
                            .Fuel & " " & _
                            .Supply & " " & _
                            .Type)
            End With
        Next
        sb.AppendLine("")
        sb.AppendLine("[Trains]")
        For intCount = 1 To Train.Length - 1
            With Train(intCount)
                sb.AppendLine(Format(intCount, "000 ") & _
                            .Ident & " " & _
                            .Unit & " " & _
                            .Side & " " & _
                            .sFrom & " " & _
                            .iFrom & " " & _
                            .sTo & " " & _
                            .iTo & " " & _
                            .Size & " " & _
                            .Curr & " " & _
                            .Direction & " " & _
                            .Troops & " " & _
                            .Fuel & " " & _
                            .Supply & " " & _
                            .Type)
            End With
        Next

        sb.AppendLine("")
        sb.AppendLine("[Rocket]")
        For intCount = 1 To Rocket.Length - 1
            With Rocket(intCount)
                sb.AppendLine(Format(intCount, "000 ") & _
                            .Active & " " & _
                            .Ident & " " & _
                            .Unit & " " & _
                            .Side & " " & _
                            .Loc & " " & _
                            .intLoc)
            End With
        Next

        sb.AppendLine("")
        sb.AppendLine("[Locations]")
        For intCount = 1 To Locat.Length - 1
            With Locat(intCount)
                sb.AppendLine(Format(intCount, "000") & " " & _
                            .Loc & " " & _
                            .Side & " " & _
                            .X & " " & _
                            .Y & " " & _
                            .Allied & " " & _
                            .Axis & " " & _
                            .Supply & " " & _
                            .Fuel & " " & _
                            .Type & " " & _
                            .Road & " " & _
                            .intRoad & " " & _
                            .AxisX & " " & _
                            .AxisY & " " & _
                            .AxisH & " " & _
                            .AlliedX & " " & _
                            .AlliedY & " " & _
                            .AlliedH)

            End With
        Next
        sb.AppendLine()
        sb.AppendLine("[Harbors]")
        For intCount = 1 To Harbor.Length - 1
            With Harbor(intCount)
                sb.AppendLine(Format(intCount, "000") & " " & _
                            .Loc & " " & _
                            .Side & " " & _
                            .X & " " & _
                            .Y & " " & _
                            .Allied & " " & _
                            .Axis & " " & _
                            .Supply & " " & _
                            .Fuel & " " & _
                            .Type & " " & _
                            .Road & " " & _
                            .intRoad & " " & _
                            .AxisX & " " & _
                            .AxisY & " " & _
                            .AxisH & " " & _
                            .AlliedX & " " & _
                            .AlliedY & " " & _
                            .AlliedH)

            End With
        Next
        sb.AppendLine()
        sb.AppendLine("[Stations]")
        For intCount = 1 To Station.Length - 1
            With Station(intCount)
                sb.AppendLine(Format(intCount, "000") & " " & _
                            .Loc & " " & _
                            .Side & " " & _
                            .X & " " & _
                            .Y & " " & _
                            .Allied & " " & _
                            .Axis & " " & _
                            .Supply & " " & _
                            .Fuel & " " & _
                            .Type & " " & _
                            .Road & " " & _
                            .intRoad & " " & _
                            .AxisX & " " & _
                            .AxisY & " " & _
                            .AxisH & " " & _
                            .AlliedX & " " & _
                            .AlliedY & " " & _
                            .AlliedH)

            End With
        Next
        sb.AppendLine("")
        sb.AppendLine("[Roads]")
        For intCount = 1 To Road.Length - 1
            With Road(intCount)
                sb.AppendLine(Format(intCount, "000 ") & _
                            .strFrom & " " & _
                            .iFrom & " " & _
                            .strTo & " " & _
                            .iTo & " " & _
                            .AxisX & " " & _
                            .AxisY & " " & _
                            .AxisH & " " & _
                            .AlliedX & " " & _
                            .AlliedY & " " & _
                            .AlliedH)
            End With
        Next
        sb.AppendLine("")
        sb.AppendLine("[Railway]")
        For intCount = 1 To Rail.Length - 1
            With Rail(intCount)
                sb.AppendLine(Format(intCount, "000 ") & _
                            .strFrom & " " & _
                            .iFrom & " " & _
                            .strTo & " " & _
                            .iTo & " " & _
                            .AxisX & " " & _
                            .AxisY & " " & _
                            .AxisH & " " & _
                            .AlliedX & " " & _
                            .AlliedY & " " & _
                            .AlliedH)
            End With
        Next
        sb.AppendLine("")
        sb.AppendLine("[Shipping Lane]")
        For intCount = 1 To ShipRoute.Length - 1
            With ShipRoute(intCount)
                sb.AppendLine(Format(intCount, "000 ") & _
                            .strFrom & " " & _
                            .iFrom & " " & _
                            .strTo & " " & _
                            .iTo & " " & _
                            .AxisX & " " & _
                            .AxisY & " " & _
                            .AxisH & " " & _
                            .AlliedX & " " & _
                            .AlliedY & " " & _
                            .AlliedH)
            End With
        Next
        sb.AppendLine("")
        sb.AppendLine("[Structures]")
        If StructInfo.Length > 1 Then
            For intCount = 1 To StructInfo.Length - 1
                With StructInfo(intCount)
                    sb.AppendLine(Format(intCount, "000 ") & _
                            .Unit & " " & _
                            .Size & " " & _
                            .Fuel & " " & _
                            .Supply & " " & _
                            .Troops & " " & _
                            .Alive & " " & _
                            .Dead)
                End With
            Next
        End If

        sb.AppendLine("")
        sb.AppendLine("[Radars]")
        If Radar.Length > 1 Then
            For intCount = 1 To Radar.Length - 1
                With Radar(intCount)
                    sb.AppendLine(Format(intCount, "000 ") & _
                            .Active & " " & _
                            .ID & " " & _
                            .Unit & " " & _
                            .Struct & " " & _
                            .X & " " & _
                            .Y & " " & _
                            .Head & " " & _
                            .Loc & " " & _
                            .intLoc)
                End With
            Next
        End If

        sb.AppendLine("")
        sb.AppendLine("[Factories]")
        If Fact.Length > 1 Then
            For intCount = 1 To Fact.Length - 1
                With Fact(intCount)
                    sb.AppendLine(Format(intCount, "000 ") & _
                            .Active & " " & _
                            .ID & " " & _
                            .Unit & " " & _
                            .Struct & " " & _
                            .X & " " & _
                            .Y & " " & _
                            .Head & " " & _
                            .Loc & " " & _
                            .intLoc)
                End With
            Next
        End If

        sb.AppendLine("")
        sb.AppendLine("[Bridges]")
        For intCount = 1 To Bridge.Length - 1
            With Bridge(intCount)
                sb.AppendLine(Format(intCount, "000 ") & _
                            .ID & " " & _
                            .sFrom & " " & _
                            .sTo)
            End With
        Next
        sb.AppendLine("")
        sb.AppendLine("[Squadrons]")
        For intCount = 1 To Squad.Length - 1
            With Squad(intCount)
                sb.AppendLine(Format(intCount, "000 ") & _
                            .Side & " " & _
                            .Squad & " " & _
                            .Coop & " " & _
                            .DF & " " & _
                            .Number & " " & _
                            .Max & " " & _
                            .Min & " " & _
                            .Loc & " " & _
                            .iLoc & " " & _
                            .Suppressed & " " & _
                            .FuelLimit & " " & _
                            .Weapon)

            End With
        Next
        sb.AppendLine("")
        sb.AppendLine("[BornPlaces]")
        For intCount = 1 To BornPlace.Length - 1
            With BornPlace(intCount)
                sb.AppendLine(Format(intCount, "000 ") & _
                            .Active & " " & _
                            .Loc & " " & _
                            .intLoc & " " & _
                            .Side & " " & _
                            .X & " " & _
                            .Y & " " & _
                            .Aircraft)
            End With
        Next
        sb.AppendLine("")
        sb.AppendLine("[FrontLine]")
        If strFrontLine.Length > 1 Then
            For intCount = 1 To strFrontLine.Length - 1
                sb.AppendLine(Format(intCount, "000 ") & _
                        strFrontLine(intCount))
            Next
        End If
        sb.AppendLine("")
        sb.AppendLine("[ACMoves]")
        If strACMove.Length > 1 Then
            For intCount = 1 To strACMove.Length - 1
                sb.AppendLine(strACMove(intCount))
            Next
        End If
        sb.AppendLine("")
        sb.AppendLine("[Stationary]")
        For intCount = 1 To Stat.Length - 1
            With Stat(intCount)
                sb.AppendLine(Format(intCount, "000 ") & _
                            .Active & " " & _
                            .Ident & " " & _
                            .Unit & " " & _
                            .Side & " " & _
                            .Loc & " " & _
                            .intLoc)
            End With
        Next
        sb.AppendLine("")
        sb.AppendLine("[Debrief]")
        If strDebrief.Length > 1 Then
            For intCount = 1 To strDebrief.Length - 1
                sb.AppendLine(strDebrief(intCount))
            Next
        End If
        sb.AppendLine("")
        Using outfile As New StreamWriter(strDebug)
            outfile.Write(sb.ToString())
            outfile.Close()
        End Using
    End Sub

    Public Sub LocateBridge(ByRef strLine As String, _
                                ByRef strID As String, _
                                ByRef Bridge() As Brid, _
                                ByRef camsettings As Campaign, _
                                ByRef MissSettings As Mission, _
                                ByRef Locat() As Location, _
                                ByRef ini_settings As INI_Class)
        Dim strFrom As String = ""
        Dim strTo As String = ""
        Dim dblX As Double
        Dim dblY As Double
        Dim iH As Integer
        Dim strCoor As String = ""
        Dim dblBridgeX As Double
        Dim dblBridgeY As Double
        Dim dblDist As Double
        Dim intCount As Integer
        Dim strInput As String = ""
        Dim strValue As String = ""
        Dim intStart As Integer
        Dim intPos As Integer
        Dim strRDSFile As String = ""
        Dim intBridge As Integer
        Dim lngCount As Long
        Dim sWP(0) As String
        Dim totWP As Integer
        Dim sInput As String = ""
        Dim filereader As IO.StreamReader
        'Finds the road where the bridge is
        If Bridge.Length > 1 Then
            For intCount = 1 To Bridge.Length - 1
                If Bridge(intCount).ID = strID Then Exit Sub
            Next
        End If
        intStart = InStr(strLine, " at ")
        If intStart > 1 Then
            intStart = intStart + 4
            strCoor = Mid(strLine, intStart)
            FindCoor(strCoor, dblBridgeX, dblBridgeY, iH)
            strRDSFile = ini_settings.sData & camsettings.RouteName & ".rds"
            If Dir(strRDSFile) = "" Then Exit Sub
            If My.Computer.FileSystem.FileExists(strRDSFile) Then
                filereader = My.Computer.FileSystem.OpenTextFileReader(strRDSFile)
                Do Until filereader.EndOfStream
                    sInput = filereader.ReadLine
                    sInput = Trim(sInput)
                    If sInput <> "" Then
                        totWP = totWP + 1
                        ReDim Preserve sWP(totWP)
                        sWP(totWP) = sInput
                    End If
                Loop
                filereader.Close()
            End If
            If totWP < 1 Then
                Exit Sub
            End If
            For lngCount = 1 To totWP

                strInput = sWP(lngCount)
                intStart = InStr(strInput, "[")
                If intStart > 0 Then
                    'find start location
                    intStart = intStart + 1
                    intPos = InStr(strInput, " to ")
                    strValue = Trim(Mid(strInput, intStart, intPos - intStart))
                    strFrom = strValue
                    intStart = intPos + 4
                    intPos = InStr(strInput, "]")
                    strValue = Trim(Mid(strInput, intStart, intPos - intStart))
                    strTo = strValue

                Else
                    If strInput <> "" Then FindCoor(strInput, _
                                            dblX, _
                                            dblY, _
                                            iH)
                    dblDist = Math.Sqrt(((dblBridgeX - dblX) ^ 2) + ((dblBridgeY - dblY) ^ 2))
                    If dblDist < 500 Then
                        'strFrom = ""
                        'strTo = ""
                        FindBridge(strID, _
                                   strFrom, _
                                   strTo, _
                                   dblX, _
                                   dblY, _
                                   intBridge, _
                                   Bridge, _
                                   Locat)
                        If intBridge = Bridge.Length - 1 And MissSettings.Bridge > 1 Then
                            DestroyBridges(intBridge, _
                                           Bridge)
                        End If
                    End If
                End If

            Next
        End If
    End Sub

    Public Sub FindBridge(ByRef strID As String, _
                            ByRef strFrom As String, _
                            ByRef strTo As String, _
                            ByRef dblX As Double, _
                            ByRef dblY As Double, _
                            ByRef intBridge As Integer, _
                            ByRef Bridge() As Brid, _
                            ByRef Locat() As Location)
        Dim intCount As Integer
        Dim iFrom As Integer
        Dim iTo As Integer
        'Finds if the bridge has already been destroyed
        For intCount = 1 To Locat.Length - 1
            If Locat(intCount).Loc = strFrom Then
                iFrom = intCount
            End If
            If Locat(intCount).Loc = strTo Then
                iTo = intCount
            End If
        Next
        If Bridge.Length < 2 Then
            intBridge = Bridge.Length
            ReDim Preserve Bridge(Bridge.Length)
            With Bridge(Bridge.Length - 1)
                .ID = strID
                .sFrom = strFrom
                .sTo = strTo
                .iFrom = iFrom
                .iTo = iTo
                .X = dblX
                .Y = dblY
            End With

        Else
            For intBridge = Bridge.Length - 1 To 1 Step -1
                If Bridge(intBridge).ID = strID And _
                    Bridge(intBridge).sFrom = strFrom And _
                    Bridge(intBridge).sTo = strTo Then Exit For
            Next
            If intBridge < 1 Then
                intBridge = Bridge.Length
                ReDim Preserve Bridge(Bridge.Length)
                With Bridge(Bridge.Length - 1)
                    .ID = strID
                    .sFrom = strFrom
                    .sTo = strTo
                    .iFrom = iFrom
                    .iTo = iTo
                    .X = dblX
                    .Y = dblY
                End With
            End If
        End If
    End Sub
    Public Sub FindRailBridge(ByRef strID As String, _
                            ByRef strFrom As String, _
                            ByRef strTo As String, _
                            ByRef dblX As Double, _
                            ByRef dblY As Double, _
                            ByRef intBridge As Integer, _
                            ByRef Bridge() As Brid, _
                            ByRef Station() As Location)
        Dim intCount As Integer
        Dim iFrom As Integer
        Dim iTo As Integer
        For intCount = 1 To Station.Length - 1
            If Station(intCount).Loc = strFrom Then
                iFrom = intCount
            End If
            If Station(intCount).Loc = strTo Then
                iTo = intCount
            End If
        Next
        If Bridge.Length < 2 Then
            intBridge = Bridge.Length
            ReDim Preserve Bridge(Bridge.Length)
            With Bridge(Bridge.Length - 1)
                .ID = strID
                .sFrom = strFrom
                .sTo = strTo
                .iFrom = iFrom
                .iTo = iTo
                .X = dblX
                .Y = dblY
            End With
        Else
            For intBridge = Bridge.Length - 1 To 1 Step -1
                If Bridge(intBridge).ID = strID And _
                    Bridge(intBridge).sFrom = strFrom And _
                    Bridge(intBridge).sTo = strTo Then Exit For
            Next
            If intBridge < 1 Then
                intBridge = Bridge.Length
                ReDim Preserve Bridge(Bridge.Length)
                With Bridge(Bridge.Length - 1)
                    .ID = strID
                    .sFrom = strFrom
                    .sTo = strTo
                    .iFrom = iFrom
                    .iTo = iTo
                    .X = dblX
                    .Y = dblY
                End With
            End If
        End If
    End Sub
    
    Public Sub RemoveACGround(ByRef strAC As String, _
                        ByRef intLoc As Integer, _
                        ByRef Squad() As Squad_Type)
        Dim intCount As Integer
        For intCount = 1 To Squad.Length - 1
            With Squad(intCount)
                If strAC = .Coop And _
                        .iLoc = intLoc And _
                        .Number > 0 Then
                    .Number = .Number - 1
                End If
            End With
        Next
    End Sub

    Public Sub AddAC(ByRef strAC As String, _
                        ByRef intLoc As Integer, _
                        ByRef Squad() As Squad_Type, _
                        ByRef UseSquad As Integer)
        Dim intCount As Integer
        If UseSquad > 0 Then Exit Sub
        'Use AC file
        For intCount = 1 To Squad.Length - 1
            With Squad(intCount)
                If strAC = .Coop Then
                    .Number = .Number + 1
                    Exit For
                End If
            End With
        Next
    End Sub
    Public Sub ConvertDF(ByRef strLine As String, _
                            ByRef strAC As String, _
                            ByRef AC_New() As AC_Type)
        Dim intStart As Integer
        Dim intPos As Integer
        intStart = InStr(strLine, ":") + 1
        strAC = Trim(Mid(strLine, intStart))
        For intPos = AC_New.Length - 1 To 1 Step -1
            If strAC = AC_New(intPos).DF Then
                strAC = AC_New(intPos).Coop
                Exit For
            End If
        Next
        If intPos < 1 Then strAC = ""
    End Sub
    Public Sub FindIDinShot(ByRef strLine As String, _
                            ByRef strID As String)
        Dim intStart As Integer
        Dim intPos As Integer
        intStart = InStr(strLine, "] ") + 1
        intPos = InStr(strLine, " shot down ")
        strID = Trim(Mid(strLine, intStart, intPos - intStart))
    End Sub
    Public Sub FindIDinAT(ByRef strLine As String, _
                            ByRef strID As String)
        Dim intStart As Integer
        Dim intPos As Integer
        intStart = InStr(strLine, "] ") + 2
        intPos = InStr(intStart, strLine, ":")
        intPos = InStr(intPos, strLine, " ")
        strID = Trim(Mid(strLine, intStart, intPos - intStart))
    End Sub
    Public Sub ProcessMission(ByRef bolerror As Boolean, _
                                ByRef strerror As String, _
                                ByRef sEventDate As String, _
                                ByRef BornPlace() As BornPlaceClass, _
                                ByRef Bridge() As Brid, _
                                ByRef Fact() As Factory, _
                                ByRef Rocket() As RocketType, _
                                ByRef camsettings As Campaign, _
                                ByRef MissSettings As Mission, _
                                ByRef Stat() As Stationary, _
                                ByRef Col() As Column, _
                                ByRef Ship() As Column, _
                                ByRef Train() As Column, _
                                ByRef Infantry() As Column, _
                                ByRef Locat() As Location, _
                                ByRef Station() As Location, _
                                ByRef Harbor() As Location, _
                                ByRef strDebrief() As String, _
                                ByRef strFrontLine() As String, _
                                ByRef strBdgDown() As String, _
                                ByRef ProcEvent As Integer, _
                                ByRef Pilot() As Plt, _
                                ByRef Squad() As Squad_Type, _
                                ByRef ActiveBridge() As String, _
                                ByRef SupplyAC() As AC_Supply, _
                                ByRef Radar() As Factory, _
                                ByRef INI_Settings As INI_Class, _
                                ByRef Manufacture() As Factory)

        FixDestroyed(bolerror, _
                     strerror, _
                     Col, _
                     Ship, _
                     Train, _
                     Infantry)
        If bolerror Then
            Exit Sub
        End If
        ProcessEvents(bolerror, _
                      strerror, _
                      sEventDate, _
                      Bridge, _
                      Fact, _
                      Rocket, _
                      camsettings, _
                      MissSettings, _
                      Stat, _
                      Col, _
                      Ship, _
                      Train, _
                      Infantry, _
                      Locat, _
                      Station, _
                      strDebrief, _
                      ProcEvent, _
                      ActiveBridge, _
                      Radar, _
                      INI_Settings, _
                      Manufacture)
        If bolerror Then
            Exit Sub
        End If

        If ProcEvent < 1 Then Exit Sub 'If not new mission exit
        ProcessEventsAC(BornPlace, _
                        MissSettings, _
                        Stat, _
                        Ship, _
                        Infantry, _
                        Locat, _
                        strDebrief, _
                        Pilot, _
                        Squad, _
                        SupplyAC, _
                        INI_Settings)
        'Generate Results File
        GenResults(BornPlace, _
                   MissSettings, _
                    Stat, _
                    Col, _
                    Ship, _
                    Train, _
                    Infantry, _
                    Locat, _
                    INI_Settings)
        CheckColumns(bolerror, _
                     strerror, _
                     MissSettings, _
                     Col, _
                     Locat, _
                     strDebrief)
        If bolerror Then
            Exit Sub
        End If
        CheckInfantry(Infantry, _
                      Locat, _
                      strDebrief)
        CheckShips(bolerror, _
                   strerror, _
                   MissSettings, _
                   Col, _
                   Ship, _
                   Harbor, _
                   strDebrief)
        If bolerror Then
            Exit Sub
        End If
        CheckTrains(bolerror, _
                    strerror, _
                    MissSettings, _
                    Col, _
                    Train, _
                    Station, _
                    strDebrief)
        If bolerror Then
            Exit Sub
        End If
        ReportBridges(bolerror, _
                      strerror, _
                      Bridge, _
                      Locat, _
                      strDebrief, _
                      strBdgDown)
        If bolerror Then
            Exit Sub
        End If
        RepairBridges(bolerror, _
                      strerror, _
                      Bridge, _
                      Col, _
                      strDebrief)
        If bolerror Then
            Exit Sub
        End If
        MoveColumns(bolerror, _
                    strerror, _
                    Bridge, _
                    Col, _
                    strDebrief)
        If bolerror Then
            Exit Sub
        End If
        MoveInfantry(Infantry)
        MoveShips(bolerror, _
                  strerror, _
                  Ship)
        If bolerror Then
            Exit Sub
        End If
        MoveTrains(bolerror, _
                   strerror, _
                   Bridge, _
                   Train, _
                   strDebrief)
        If bolerror Then
            Exit Sub
        End If

        Set_Sides_At_Locations(bolerror, _
                       strerror, _
                       Rocket, _
                       Stat, _
                       Col, _
                       Ship, _
                       Train, _
                       Locat, _
                       Station, _
                       Harbor, _
                       strFrontLine, _
                       Infantry, _
                       MissSettings)
        Set_Sides_At_Stations(bolerror, _
                       strerror, _
                       Rocket, _
                       Stat, _
                       Col, _
                       Ship, _
                       Train, _
                       Locat, _
                       Station, _
                       Harbor, _
                       strFrontLine, _
                       Infantry, _
                       MissSettings)
        Set_Sides_At_Harbors(bolerror, _
                       strerror, _
                       Rocket, _
                       Stat, _
                       Col, _
                       Ship, _
                       Train, _
                       Locat, _
                       Station, _
                       Harbor, _
                       strFrontLine, _
                       Infantry, _
                       MissSettings)
        UpdateHarbors(Ship, _
                      Harbor)
    End Sub
    Public Sub CheckColumns(ByRef bolerror As Boolean, _
                            ByRef strerror As String, _
                            ByRef MissSettings As Mission, _
                            ByRef Col() As Column, _
                            ByRef Locat() As Location, _
                            ByRef strDebrief() As String)
        'Checks the columns to see if any have been destroyed
        Dim intCount As Integer
        Dim intStart As Integer
        Dim intCntCols As Integer
        Dim strUnit As String
        Dim strOutput As String
        For intCount = 1 To Col.Length - 1

            With Col(intCount)
                intStart = InStr(.Unit, "Armor.")
                If intStart < 1 Then intStart = InStr(.Unit, "Infantry.")
                If intStart > 0 Then
                    'deal with a tank column
                    If .Size > .Curr Then
                        .Unit = Replace(.Unit, Chr(48 + .Size), Chr(48 + .Curr), 1, 1)
                        .Size = .Curr
                    End If
                Else
                    'deal with a different type of column
                    If .Curr > 0 Then
                        If .Curr / .Size <= MissSettings.Convoy Then
                            .Curr = 0
                        End If
                    End If
                End If
                If .Curr < 1 Then
                    intStart = InStr(.Unit, ".") + 1
                    strUnit = Mid(.Unit, intStart)
                    If .iFrom > 0 Then
                        strOutput = ""
                        FindGrid(Locat(.iFrom).X, Locat(.iFrom).Y, strOutput)
                        ReDim Preserve strDebrief(strDebrief.Length)
                        strDebrief(strDebrief.Length - 1) = strUnit & " at " & .sFrom & strOutput
                    End If
                    .sFrom = "Destroyed"
                    .sTo = "Destroyed"
                    .iFrom = 0
                    .iTo = 0
                    .Curr = .Size
                    RestoreOrigCol(.Unit, .Orig)
                    If .Columns > 0 Then
                        For intCntCols = 1 To Col.Length - 1
                            If Col(intCntCols).sFrom = .Ident Then
                                Col(intCntCols).sFrom = "Destroyed"
                                Col(intCntCols).sTo = "Destroyed"
                                Col(intCntCols).iFrom = 0
                                Col(intCntCols).iTo = 0
                                RestoreOrigCol(Col(intCntCols).Unit, Col(intCntCols).Orig)
                            End If
                        Next
                    End If
                End If
            End With
        Next
    End Sub
    Public Sub ReportBridges(ByRef bolerror As Boolean, _
                                ByRef strerror As String, _
                                ByRef Bridge() As Brid, _
                                ByRef Locat() As Location, _
                                ByRef strDebrief() As String, _
                                ByRef strBdgDown() As String)
        Dim intCount As Integer
        Dim strOutput As String
        Dim strFrom As String
        Dim strTo As String
        If Bridge.Length > 1 Then
            For intCount = 1 To Bridge.Length - 1
                With Bridge(intCount)
                    strFrom = ""
                    strTo = ""
                    FindGrid(Locat(.iFrom).X, Locat(.iFrom).Y, strFrom)
                    FindGrid(Locat(.iTo).X, Locat(.iTo).Y, strTo)
                    strOutput = .ID & " from " & .sFrom & " " & strFrom & " to " & .sTo & " " & strTo
                End With
                ReDim Preserve strDebrief(strDebrief.Length)
                strDebrief(strDebrief.Length - 1) = strOutput
                ReDim Preserve strBdgDown(strBdgDown.Length)
                strBdgDown(strBdgDown.Length - 1) = strOutput
            Next
        End If
    End Sub


    Public Sub Set_Sides_At_Locations(ByRef bolerror As Boolean, _
                                ByRef strerror As String, _
                                ByRef Rocket() As RocketType, _
                                ByRef Stat() As Stationary, _
                                ByRef Col() As Column, _
                                ByRef Ship() As Column, _
                                ByRef Train() As Column, _
                                ByRef Locat() As Location, _
                                ByRef Station() As Location, _
                                ByRef Harbor() As Location, _
                                ByRef strFrontLine() As String, _
                                ByRef Infantry() As Column, _
                                ByRef MissSettings As Mission)
        Dim intCount As Integer 'Column Counter
        Dim sAllied As Single
        Dim sAxis As Single
        'This sub checks the columns at each location and decides if the location is
        'allied, axis or contested
        If Locat.Length < 2 Then
            Exit Sub
        End If
        For intCount = 1 To Locat.Length - 1
            Locat(intCount).Axis = 0
            Locat(intCount).Allied = 0
        Next
        If Stat.Length > 1 Then
            For intCount = 1 To Stat.Length - 1
                With Stat(intCount)
                    If .Active Then
                        If .Side = 1 Then
                            If InStr(.Unit, "vehicles.artillery") > 0 Or _
                                    InStr(.Unit, "ships.Ship$") > 0 Then
                                If InStr(.Unit, "vehicles.artillery") > 0 Then
                                    Locat(.intLoc).Allied += ptAAA
                                Else
                                    Locat(.intLoc).Allied += ptShip
                                End If
                            Else
                                If InStr(.Unit, "vehicles.stationary.Siren") < 1 And _
                                        InStr(.Unit, "planes.Plane$") < 1 Then
                                    Locat(.intLoc).Allied += ptCar
                                End If
                            End If
                        End If
                        If .Side = 2 Then
                            If InStr(.Unit, "vehicles.artillery") > 0 Or _
                                    InStr(.Unit, "ships.Ship$") > 0 Then
                                If InStr(.Unit, "vehicles.artillery") > 0 Then
                                    Locat(.intLoc).Axis += ptAAA
                                Else
                                    Locat(.intLoc).Axis += ptShip
                                End If
                            Else
                                If InStr(.Unit, "vehicles.stationary.Siren") < 1 And _
                                        InStr(.Unit, "planes.Plane$") < 1 Then
                                    Locat(.intLoc).Axis += ptCar
                                End If
                            End If
                        End If
                    End If
                End With
            Next
        End If
        If Rocket.Length > 1 Then
            For intCount = 1 To Rocket.Length - 1 'Check for rockets
                With Rocket(intCount)
                    If .Active Then
                        If .Side = 1 Then
                            Locat(.intLoc).Allied += ptRocket
                        End If
                        If .Side = 2 Then
                            Locat(.intLoc).Axis += ptRocket
                        End If
                    End If
                End With
            Next
        End If
        If Col.Length > 1 Then
            For intCount = 1 To Col.Length - 1
                With Col(intCount)
                    If .iFrom > 0 Then
                        If .Side = 1 Then
                            If .ConType > 0 Then
                                'Locat(.iFrom).Allied += Int(.Troops * .Curr / .Size)
                                Locat(.iFrom).Allied += Int(.Troops * .Curr / .OrigSize)
                            Else
                                Locat(.iFrom).Allied += .Curr * ptTank
                            End If
                        End If
                        If .Side = 2 Then
                            If .ConType > 0 Then
                                'Locat(.iFrom).Axis += Int(.Troops * .Curr / .Size)
                                Locat(.iFrom).Axis += Int(.Troops * .Curr / .OrigSize)
                            Else
                                Locat(.iFrom).Axis += .Curr * ptTank
                            End If
                        End If
                    End If
                End With
            Next
        End If
        If Infantry.Length > 1 Then
            For intCount = 1 To Infantry.Length - 1
                With Infantry(intCount)
                    If .iFrom > 0 Then
                        If .Side = 1 Then
                            Locat(.iFrom).Allied += .Curr
                        End If
                        If .Side = 2 Then
                            Locat(.iFrom).Axis += .Curr
                        End If
                    End If
                End With
            Next
        End If
        'Set Side for Location
        For intCount = 1 To Locat.Length - 1
            With Locat(intCount)
                sAllied = .Allied / (.Allied + .Axis)
                sAxis = .Axis / (.Allied + .Axis)
                If .Allied + .Axis > 0 Then
                    If sAllied >= MissSettings.Contested _
                                And sAxis >= MissSettings.Contested Then
                        .Side = 0
                        ReDim Preserve strFrontLine(strFrontLine.Length)
                        strFrontLine(strFrontLine.Length - 1) = .Loc
                    Else
                        If sAllied >= MissSettings.Contested Then .Side = 1
                        If sAxis >= MissSettings.Contested Then .Side = 2
                    End If
                End If
            End With
        Next

        'Update Supplies and Fuel at Locations
        For intCount = 1 To Col.Length - 1
            With Col(intCount)
                If .iFrom > 0 Then
                    If .Side = Locat(.iFrom).Side Then
                        Locat(.iFrom).Supply += Int(.Supply * .Curr / .Size)
                        Locat(.iFrom).Fuel += Int(.Fuel * .Curr / .Size)
                    End If
                End If
            End With
        Next


    End Sub
    Public Sub Set_Sides_At_Stations(ByRef bolerror As Boolean, _
                                ByRef strerror As String, _
                                ByRef Rocket() As RocketType, _
                                ByRef Stat() As Stationary, _
                                ByRef Col() As Column, _
                                ByRef Ship() As Column, _
                                ByRef Train() As Column, _
                                ByRef Locat() As Location, _
                                ByRef Station() As Location, _
                                ByRef Harbor() As Location, _
                                ByRef strFrontLine() As String, _
                                ByRef Infantry() As Column, _
                                ByRef MissSettings As Mission)
        Dim intCount As Integer 'Column Counter
        'This sub checks the columns at each station and decides if the station is
        'allied, axis or contested
        If Station.Length < 2 Then
            Exit Sub
        End If
        'Set Side for Stations
        For intCount = 1 To Station.Length - 1
            With Station(intCount)
                .Side = Locat(.intRoad).Side
            End With
        Next
        'Update Supplies and fuel at Stations
        For intCount = 1 To Train.Length - 1
            With Train(intCount)
                If .iFrom > 0 Then
                    If .Side = Station(.iFrom).Side Then
                        Locat(Station(.iFrom).intRoad).Supply += Int(.Supply * .Curr / .Size)
                        Locat(Station(.iFrom).intRoad).Fuel += Int(.Fuel * .Curr / .Size)
                    End If
                End If
            End With
        Next
    End Sub
    Public Sub Set_Sides_At_Harbors(ByRef bolerror As Boolean, _
                                ByRef strerror As String, _
                                ByRef Rocket() As RocketType, _
                                ByRef Stat() As Stationary, _
                                ByRef Col() As Column, _
                                ByRef Ship() As Column, _
                                ByRef Train() As Column, _
                                ByRef Locat() As Location, _
                                ByRef Station() As Location, _
                                ByRef Harbor() As Location, _
                                ByRef strFrontLine() As String, _
                                ByRef Infantry() As Column, _
                                ByRef MissSettings As Mission)
        Dim intCount As Integer 'Column Counter
        'This sub checks the columns at each harbor and decides if the harbor is
        'allied, axis or contested
        If Harbor.Length < 2 Then
            Exit Sub
        End If
        'Set Side for Harbors
        For intCount = 1 To Harbor.Length - 1
            With Harbor(intCount)
                If InStr(.Loc, "_Sea") > 0 Then
                    If .Axis > 0 And .Allied > 0 Then
                        .Side = 0
                    Else
                        If .Axis > 0 And .Allied < 1 Then .Side = 2
                        If .Axis < 1 And .Allied > 0 Then .Side = 1
                    End If
                Else
                    .Side = Locat(.intRoad).Side
                End If
            End With
        Next


        'Update Supplies and fuel at Harbors
        For intCount = 1 To Ship.Length - 1
            With Ship(intCount)
                If .iFrom > 0 Then
                    If .Side = Harbor(.iFrom).Side And InStr(Harbor(.iFrom).Loc, "_Sea") < 1 Then
                        Locat(Harbor(.iFrom).intRoad).Supply += Int(.Supply * .Curr / .Size)
                        Locat(Harbor(.iFrom).intRoad).Fuel += Int(.Fuel * .Curr / .Size)
                    End If
                End If
            End With
        Next

    End Sub
    Public Sub FindRoadLoc(ByRef bolerror As Boolean, _
                            ByRef strerror As String, _
                            ByRef Locat() As Location, _
                            ByRef Station() As Location, _
                            ByRef Harbor() As Location)

        Dim intLoc As Integer
        Dim intCount As Integer
        Dim dblDist As Double
        Dim dblTemp As Double
        Dim intStart As Integer
        'This sub finds the Road Loaction associated with a station or harbor
        If Locat.Length < 2 Then
            bolerror = True
            strerror = "No locations found in -FindRoadLoc-"
        End If

        If Harbor.Length > 1 Then
            For intCount = 1 To Harbor.Length - 1
                intStart = InStr(Harbor(intCount).Loc, "Harbor")
                If InStr(Harbor(intCount).Loc, "_Harbor") > 0 Or _
                    InStr(Harbor(intCount).Loc, "_Beachhead") Or _
                    InStr(Harbor(intCount).Loc, "_Sea") > 0 Then
                    For intLoc = 1 To Locat.Length - 1
                        dblTemp = Math.Sqrt(((Locat(intLoc).X - Harbor(intCount).X) ^ 2) + _
                                        ((Locat(intLoc).Y - Harbor(intCount).Y) ^ 2))
                        If intLoc = 1 Then
                            Harbor(intCount).Road = Locat(intLoc).Loc
                            Harbor(intCount).intRoad = intLoc
                            Harbor(intCount).Side = Locat(intLoc).Side
                            dblDist = dblTemp
                        Else
                            If dblTemp < dblDist Then
                                Harbor(intCount).Road = Locat(intLoc).Loc
                                Harbor(intCount).intRoad = intLoc
                                Harbor(intCount).Side = Locat(intLoc).Side
                                dblDist = dblTemp
                            End If
                        End If
                    Next
                End If
            Next
        End If
        If Station.Length > 1 Then
            For intCount = 1 To Station.Length - 1
                intStart = InStr(Station(intCount).Loc, "Station")
                If intStart > 0 Then
                    For intLoc = 1 To Locat.Length - 1
                        dblTemp = Math.Sqrt(((Locat(intLoc).X - Station(intCount).X) ^ 2) + _
                                        ((Locat(intLoc).Y - Station(intCount).Y) ^ 2))
                        If intLoc = 1 Then
                            Station(intCount).Road = Locat(intLoc).Loc
                            Station(intCount).intRoad = intLoc
                            Station(intCount).Side = Locat(intLoc).Side
                            dblDist = dblTemp
                        Else
                            If dblTemp < dblDist Then
                                Station(intCount).Road = Locat(intLoc).Loc
                                Station(intCount).intRoad = intLoc
                                Station(intCount).Side = Locat(intLoc).Side
                                dblDist = dblTemp
                            End If
                        End If
                    Next
                End If
            Next
        End If
    End Sub

    Public Sub UpdateStatics(ByRef bolerror As Boolean, _
                            ByRef strerror As String, _
                            ByRef Stat() As Stationary, _
                            ByRef Locat() As Location)
        Dim intStatCnt As Integer
        Dim intSubtract As Integer
        If Stat.Length < 2 Then
            bolerror = True
            strerror = "Cannot find statics - UpdateStatics -"
            Exit Sub
        End If
        For intStatCnt = 1 To Stat.Length - 1
            With Stat(intStatCnt)
                If Not .Active Then
                    intSubtract = 1
                    If InStr(.Unit, "stationary.Siren$") > 0 Then intSubtract = 0
                    If .Unit.Contains("Ship$Factory") Then intSubtract = 0
                    If InStr(.Unit, "planes.Plane$") > 0 Then intSubtract = -1
                    If InStr(.Unit, "vehicles.artillery") > 0 Then intSubtract = 5
                    If .Unit.Contains("ships.Ship$") And Not .Unit.Contains("Ship$Factory") Then intSubtract = 10
                    If .Side < 1 Then intSubtract = 0
                    If intSubtract > 0 Then
                        If Locat(.intLoc).Supply > 0 And _
                                .Side = Locat(.intLoc).Side Then
                            If intSubtract <= Locat(.intLoc).Supply Then
                                .Active = True
                                Locat(.intLoc).Supply = Locat(.intLoc).Supply - intSubtract
                                If .Side = 1 Then
                                    Locat(.intLoc).Allied = Locat(.intLoc).Allied + intSubtract
                                Else
                                    Locat(.intLoc).Axis = Locat(.intLoc).Axis + intSubtract
                                End If
                            End If
                            If Locat(.intLoc).Supply < 0 Then Locat(.intLoc).Supply = 0
                        End If
                    Else
                        If Locat(.intLoc).Side = .Side Or .Side < 1 Then .Active = True
                        If intSubtract < 0 Then .Active = False
                    End If
                End If
            End With
        Next
    End Sub
    Public Sub PrepareNextMission(ByRef bolerror As Boolean, _
                        ByRef strerror As String, _
                        ByRef ColLoc() As String, _
                        ByRef MisWeather As Integer, _
                        ByRef MisCloud As Integer, _
                        ByRef wind As Weather, _
                        ByRef BornPlace() As BornPlaceClass, _
                        ByRef Bridge() As Brid, _
                        ByRef Fact() As Factory, _
                        ByRef Rocket() As RocketType, _
                        ByRef camsettings As Campaign, _
                        ByRef MissSettings As Mission, _
                        ByRef Stat() As Stationary, _
                        ByRef Col() As Column, _
                        ByRef Ship() As Column, _
                        ByRef Train() As Column, _
                        ByRef Infantry() As Column, _
                        ByRef Locat() As Location, _
                        ByRef Station() As Location, _
                        ByRef Harbor() As Location, _
                        ByRef Road() As Waypoint, _
                        ByRef ShipRoute() As Waypoint, _
                        ByRef Rail() As Waypoint, _
                        ByRef Trail() As Waypoint, _
                        ByRef strDebrief() As String, _
                        ByRef RouteStart(,) As Integer, _
                        ByRef AC_New() As AC_Type, _
                        ByRef Squad() As Squad_Type, _
                        ByRef UseSquad As Integer, _
                        ByRef Radar() As Factory, _
                        ByRef INI_Settings As INI_Class, _
                        ByRef MisTime As Single, _
                        ByRef Weapons() As Weap, _
                        ByRef Manufacture() As Factory)
        UpdateStatics(bolerror, _
                      strerror, _
                      Stat, _
                      Locat)
        If bolerror Then Exit Sub
        UpdateRocket(bolerror, _
                     strerror, _
                     Rocket, _
                     Locat, _
                     strDebrief)
        If bolerror Then Exit Sub
        UpdateRadars(Locat, _
                     Radar)

        UnLoadTrain(bolerror, _
                    strerror, _
                    Col, _
                    Train, _
                    Locat, _
                    Station, _
                    Rail, _
                    RouteStart, _
                    Infantry, _
                    ColLoc)
        If bolerror Then Exit Sub
        LoadColOnTrain(bolerror, _
                       strerror, _
                       Col, _
                       Train, _
                       Infantry, _
                       Locat, _
                       Station, _
                       Rail, _
                       ColLoc)
        If bolerror Then Exit Sub
        UpdateTrains(bolerror, _
                     strerror, _
                     ColLoc, _
                     Bridge, _
                     MissSettings, _
                     Train, _
                     Station, _
                     Rail, _
                     strDebrief, _
                     RouteStart, _
                     INI_Settings)
        If bolerror Then Exit Sub

        UpdateColumns(bolerror, _
                      strerror, _
                      ColLoc, _
                      Bridge, _
                      MissSettings, _
                      Col, _
                      Locat, _
                      Road, _
                      strDebrief, _
                      RouteStart, _
                      INI_Settings)
        If bolerror Then Exit Sub
        UpdateInfantry(ColLoc, _
                       Bridge, _
                       MissSettings, _
                       Infantry, _
                       Locat, _
                       Trail, _
                       strDebrief, _
                       RouteStart, _
                       INI_Settings)
        UnLoadShip(bolerror, _
                   strerror, _
                   camsettings, _
                   Col, _
                   Ship, _
                   Infantry, _
                   Locat, _
                   Harbor, _
                   RouteStart, _
                   ColLoc)
        If bolerror Then Exit Sub
        LoadColOnShip(bolerror, _
                      strerror, _
                      camsettings, _
                      Col, _
                      Ship, _
                      Infantry, _
                      Locat, _
                      Harbor, _
                      RouteStart, _
                      ColLoc)
        If bolerror Then Exit Sub
        UpdateShips(bolerror, _
                    strerror, _
                    ColLoc, _
                    camsettings, _
                    Ship, _
                    Harbor, _
                    ShipRoute, _
                    strDebrief, _
                    RouteStart, _
                    INI_Settings)
        If bolerror Then Exit Sub
        Check_Supply_Base(BornPlace, _
                          camsettings, _
                          Squad, _
                          AC_New, _
                          Locat, _
                          Weapons)

        If UseSquad > 0 Then
            UpdateSquadrons(bolerror, _
                            strerror, _
                            BornPlace, _
                            camsettings, _
                            Ship, _
                            Locat, _
                            Squad, _
                            INI_Settings)
            If bolerror Then Exit Sub
        Else
            Update_Squads(BornPlace, _
                          camsettings, _
                          Locat, _
                          AC_New, _
                          Squad)
        End If
        'GndAircraft(bolerror, _
        '            strerror, _
        '            Stat, _
        '            Locat, _
        '           Squad)
        If bolerror Then Exit Sub
        CleanUpStat(bolerror, _
                    strerror, _
                    Stat, _
                    Locat)
        If bolerror Then Exit Sub
        CleanUpRocket(bolerror, _
                      strerror, _
                      Rocket, _
                      Locat)
        If bolerror Then Exit Sub
        CleanUpFact(bolerror, _
                    strerror, _
                    Fact, _
                    Locat)
        If bolerror Then Exit Sub
        Manufacture_Units(bolerror, _
                    strerror, _
                    Fact, _
                    Col, _
                    Locat, _
                    INI_Settings, _
                    Infantry, _
                    Manufacture, _
                    ColLoc)
        If bolerror Then Exit Sub
        RepairFactories(bolerror, _
                        strerror, _
                        Fact, _
                        MissSettings, _
                        Locat, _
                        strDebrief, _
                        Manufacture)
        If bolerror Then Exit Sub
        ShowSupply(bolerror, _
                   strerror, _
                   Fact, _
                   Locat)
        If bolerror Then Exit Sub
        RepairColumns(Col, _
                      Locat, _
                       INI_Settings)
        RepairTrains(Train, _
                     Locat, _
                     Station, _
                     INI_Settings)
        RepairShips(Ship, _
                    Locat, _
                    Harbor, _
                    INI_Settings)
        Cleanup_Troops(Rocket, _
                       Stat, _
                       Col, _
                       Locat, _
                       Infantry)
        Check_Suppression(MissSettings, _
                          Locat)
        SetConditions(MisTime, _
                         MisWeather, _
                         MisCloud, _
                         wind, _
                         MissSettings)
        AdvanceDate(bolerror, _
                    strerror, _
                    camsettings)

    End Sub

    Public Sub LoadBldgFile(ByRef bolerror As Boolean, _
                        ByRef strerror As String, _
                        ByRef Locat() As Location, _
                        ByRef Bldg() As Stationary, _
                        ByRef INI_Settings As INI_Class)

        Dim strBldgFile As String
        Dim strInput As String
        Dim intPos As Integer
        Dim intStart As Integer
        Dim filereader As IO.StreamReader
        strBldgFile = INI_Settings.sCampaign & "\buildings.dcg"
        If Dir(strBldgFile) = "" Then
            bolerror = True
            strerror = "Cannot find Building file!"
            Exit Sub
        End If
        If My.Computer.FileSystem.FileExists(strBldgFile) Then
            filereader = My.Computer.FileSystem.OpenTextFileReader(strBldgFile)
            Do Until filereader.EndOfStream
                strInput = filereader.ReadLine
                intStart = InStr(strInput, "_bld")
                If intStart > 0 Then
                    ReDim Preserve Bldg(Bldg.Length)
                    Bldg(Bldg.Length - 1).Active = True
                    strInput = Trim(strInput)
                    intStart = 1
                    intPos = InStr(intStart, strInput, " ")
                    Bldg(Bldg.Length - 1).Ident = Trim(Mid(strInput, intStart, intPos - intStart))
                    intStart = intPos + 1
                    intPos = InStr(intStart, strInput, " ")
                    Bldg(Bldg.Length - 1).Unit = Trim(Mid(strInput, intStart, intPos - intStart))
                    intStart = intPos + 1
                    intPos = InStr(intStart, strInput, " ")
                    Bldg(Bldg.Length - 1).Side = Val(Mid(strInput, intStart, intPos - intStart))
                    intStart = intPos + 1
                    intPos = InStr(intStart, strInput, " ")
                    Bldg(Bldg.Length - 1).X = Val(Mid(strInput, intStart, intPos - intStart))
                    intStart = intPos + 1
                    intPos = InStr(intStart, strInput, " ")
                    Bldg(Bldg.Length - 1).Y = Val(Mid(strInput, intStart, intPos - intStart))
                    intStart = intPos + 1
                    Bldg(Bldg.Length - 1).Head = Val(Mid(strInput, intStart))
                    intStart = intPos + 1
                    intPos = InStr(intStart, strInput, " ")
                    Bldg(Bldg.Length - 1).Other = Trim(Mid(strInput, intStart))
                    FindWayPoint(Bldg(Bldg.Length - 1).X, _
                                    Bldg(Bldg.Length - 1).Y, _
                                    Bldg(Bldg.Length - 1).Loc, _
                                    Bldg(Bldg.Length - 1).intLoc, _
                                    Locat)
                End If
            Loop
            filereader.Close()
        End If
    End Sub


    Public Sub FindRouteStart(ByRef bolerror As Boolean, _
                                ByRef strerror As String, _
                                ByRef camsettings As Campaign, _
                                ByRef Locat() As Location, _
                                ByRef Road() As Waypoint, _
                                ByRef ShipRoute() As Waypoint, _
                                ByRef Rail() As Waypoint, _
                                ByRef RouteStart(,) As Integer)
        Dim intRoute As Integer
        Dim intLoc As Integer
        Dim intStart As Integer
        Dim bolFound As Boolean
        'Dim strTemp As String
        'Find Road Start/End
        intRoute = 1
        Do
            For intStart = 1 To Road.Length - 1
                intLoc = Road(intStart).iFrom
                bolFound = False
                For intRoute = 1 To Road.Length - 1
                    If intLoc = Road(intRoute).iTo Then
                        bolFound = True
                    End If
                Next
                If Not bolFound Then
                    RouteStart(2, 1) = intLoc
                    Exit Do
                End If
            Next
        Loop
        'strTemp = Locat(RouteStart(2, 1)).Loc
        Do
            For intStart = Road.Length - 1 To 1 Step -1
                intLoc = Road(intStart).iTo
                bolFound = False
                For intRoute = Road.Length - 1 To 1 Step -1
                    If intLoc = Road(intRoute).iFrom Then
                        bolFound = True
                    End If
                Next
                If Not bolFound Then
                    RouteStart(1, 1) = intLoc
                    Exit Do
                End If
            Next
        Loop
        'strTemp = Locat(RouteStart(1, 1)).Loc
        'find Rail start/end
        If Rail.Length > 1 Then
            Do
                For intStart = 1 To Rail.Length - 1
                    intLoc = Rail(intStart).iFrom
                    bolFound = False
                    For intRoute = 1 To Rail.Length - 1
                        If intLoc = Rail(intRoute).iTo Then
                            bolFound = True
                        End If
                    Next
                    If Not bolFound Then
                        RouteStart(2, 2) = intLoc
                        Exit Do
                    End If
                Next
            Loop
            'strTemp = Locat(RouteStart(2, 2)).Loc
            Do
                For intStart = Rail.Length - 1 To 1 Step -1
                    intLoc = Rail(intStart).iTo
                    bolFound = False
                    For intRoute = Rail.Length - 1 To 1 Step -1
                        If intLoc = Rail(intRoute).iFrom Then
                            bolFound = True
                        End If
                    Next
                    If Not bolFound Then
                        RouteStart(1, 2) = intLoc
                        Exit Do
                    End If
                Next
            Loop
            'strTemp = Locat(RouteStart(1, 2)).Loc
        End If
        'Find Ship Start/End
        If ShipRoute.Length > 1 Then
            Do
                For intStart = 1 To ShipRoute.Length - 1
                    intLoc = ShipRoute(intStart).iFrom
                    bolFound = False
                    For intRoute = 1 To ShipRoute.Length - 1
                        If intLoc = ShipRoute(intRoute).iTo Then
                            bolFound = True
                        End If
                    Next
                    If Not bolFound Then
                        RouteStart(2, 3) = intLoc
                        Exit Do
                    End If
                Next
            Loop
            'strTemp = Locat(RouteStart(2, 3)).Loc
            Do
                For intStart = ShipRoute.Length - 1 To 1 Step -1
                    intLoc = ShipRoute(intStart).iTo
                    bolFound = False
                    For intRoute = ShipRoute.Length - 1 To 1 Step -1
                        If intLoc = ShipRoute(intRoute).iFrom Then
                            bolFound = True
                        End If
                    Next
                    If Not bolFound Then
                        RouteStart(1, 3) = intLoc
                        Exit Do
                    End If
                Next
            Loop
            'strTemp = locate(RouteStart(1, 3)).Loc
        End If
        If camsettings.DeZone <> "" Then
            For intLoc = 1 To Locat.Length - 1
                If camsettings.DeZone = Locat(intLoc).Loc Then
                    RouteStart(2, 1) = intLoc
                End If
            Next
        End If
        If camsettings.RuZone <> "" Then
            For intLoc = 1 To Locat.Length - 1
                If camsettings.RuZone = Locat(intLoc).Loc Then
                    RouteStart(1, 1) = intLoc
                End If
            Next
        End If
    End Sub

    Public Sub MoveColumns(ByRef bolerror As Boolean, _
                                ByRef strerror As String, _
                                ByRef Bridge() As Brid, _
                                ByRef Col() As Column, _
                                ByRef strDebrief() As String)
        Dim intCount As Integer
        Dim intCnt2 As Integer
        Dim strOutput As String

        Dim intStart As Integer
        If Col.Length < 2 Then Exit Sub
        If Bridge.Length > 1 Then
            For intCount = 1 To Bridge.Length - 1
                For intCnt2 = 1 To Col.Length - 1
                    With Col(intCnt2)
                        If .Amp < 1 Then
                            If (.sFrom = Bridge(intCount).sTo And _
                                    .sTo = Bridge(intCount).sFrom) Or _
                                    (.sTo = Bridge(intCount).sTo And _
                                    .sFrom = Bridge(intCount).sFrom) Then
                                .sTo = .sFrom
                                .iTo = .iFrom
                                ReDim Preserve strDebrief(strDebrief.Length)
                                intStart = InStr(.Unit, ".") + 1
                                strOutput = Mid(.Unit, intStart)
                                strOutput = strOutput & " delayed by " & Bridge(intCount).ID
                                strDebrief(strDebrief.Length - 1) = strOutput
                            End If
                        End If
                    End With
                Next
            Next
        End If

        For intCnt2 = 1 To Col.Length - 1
            With Col(intCnt2)
                .sFrom = .sTo
                .iFrom = .iTo
            End With
        Next
    End Sub

    Public Sub UpdateColumns(ByRef bolerror As Boolean, _
                            ByRef strerror As String, _
                            ByRef ColLoc() As String, _
                            ByRef Bridge() As Brid, _
                            ByRef MissSettings As Mission, _
                            ByRef Col() As Column, _
                            ByRef Locat() As Location, _
                            ByRef Road() As Waypoint, _
                            ByRef strDebrief() As String, _
                            ByRef RouteStart(,) As Integer, _
                            ByRef INI_Settings As INI_Class)

        Dim intCol As Integer
        Dim intLoc As Integer
        Dim sngRnd As Single
        Dim intPosTo As Integer
        Dim PosTo(0) As Waypoint
        Dim intCntBdg As Integer
        Dim intBdgOut As Integer 'Column halted by bridge
        Dim intCount As Integer
        Dim strOutput As String
        'This sub decides if a column willl move to the next location
        If Col.Length < 2 Then
            bolerror = True
            strerror = "No columns found by -UpdateColumns-"
            Exit Sub
        End If
        For intCol = 1 To Col.Length - 1
            intBdgOut = 0
            ReDim Preserve ColLoc(ColLoc.Length)
            ColLoc(ColLoc.Length - 1) = Col(intCol).Ident
            Select Case Col(intCol).sFrom

                Case Is = "Blank"
                    sngRnd = Rnd()
                    If sngRnd < INI_Settings.ColumnSpawn Then
                        With Col(intCol)
                            If Locat(RouteStart(.Side, 1)).Side = .Side Then
                                .sFrom = Locat(RouteStart(.Side, 1)).Loc
                                .sTo = Locat(RouteStart(.Side, 1)).Loc
                                .iFrom = RouteStart(.Side, 1)
                                .iTo = RouteStart(.Side, 1)
                                .Direction = 1
                                .AllowLoad = 1
                            End If
                        End With
                        ColLoc(ColLoc.Length - 1) = ColLoc(ColLoc.Length - 1) & " @" & Col(intCol).sFrom
                    End If
                Case Is = "Destroyed"

                Case Else
                    'Move Convoy or Car Column
                    ColLoc(ColLoc.Length - 1) = ColLoc(ColLoc.Length - 1) & " @" & Col(intCol).sFrom
                    If Col(intCol).iFrom > 0 Then
                        If Col(intCol).Side = Locat(Col(intCol).iFrom).Side And _
                            (Locat(Col(intCol).iFrom).Fuel >= 1 Or InStr(Col(intCol).Unit, "Infantry") > 0) Then
                            intPosTo = 0

                            Select Case Col(intCol).Side
                                Case 1
                                    For intLoc = 1 To Road.Length - 1
                                        If Road(intLoc).iTo = Col(intCol).iFrom Then
                                            If Bridge.Length > 1 And _
                                                Col(intCol).Amp < 1 And _
                                                MissSettings.Bridge > 1 Then
                                                For intCntBdg = Bridge.Length - 1 To 1 Step -1
                                                    If Road(intLoc).strTo = Bridge(intCntBdg).sTo And _
                                                        Road(intLoc).strFrom = Bridge(intCntBdg).sFrom Then
                                                        intBdgOut = intBdgOut + 1
                                                        Exit For
                                                    End If
                                                Next
                                            Else
                                                intCntBdg = 0
                                            End If
                                            If intCntBdg < 1 Then
                                                intPosTo = intPosTo + 1
                                                ReDim Preserve PosTo(intPosTo)
                                                PosTo(intPosTo).iTo = Road(intLoc).iFrom
                                                PosTo(intPosTo).strTo = Road(intLoc).strFrom
                                            End If
                                        End If
                                    Next


                                Case 2
                                    For intLoc = 1 To Road.Length - 1
                                        If Road(intLoc).iFrom = Col(intCol).iFrom Then
                                            If Bridge.Length > 1 And _
                                                Col(intCol).Amp < 1 And _
                                                MissSettings.Bridge > 1 Then
                                                For intCntBdg = Bridge.Length - 1 To 1 Step -1
                                                    If Road(intLoc).strTo = Bridge(intCntBdg).sTo And _
                                                        Road(intLoc).strFrom = Bridge(intCntBdg).sFrom Then
                                                        Exit For
                                                    End If
                                                Next
                                            Else
                                                intCntBdg = 0
                                            End If
                                            If intCntBdg < 1 Then
                                                intPosTo = intPosTo + 1
                                                ReDim Preserve PosTo(intPosTo)
                                                PosTo(intPosTo).iTo = Road(intLoc).iTo
                                                PosTo(intPosTo).strTo = Road(intLoc).strTo
                                            End If
                                        End If
                                    Next
                            End Select

                            If intPosTo > 0 Then
                                sngRnd = Rnd() * intPosTo
                                intLoc = Int(sngRnd + 1)
                                intLoc = PosTo(intLoc).iTo
                                Col(intCol).iTo = intLoc
                                Col(intCol).sTo = Locat(intLoc).Loc
                                If Col(intCol).iTo <> Col(intCol).iFrom And InStr(Col(intCol).Unit, "Infantry") = 0 Then
                                    Locat(Col(intCol).iFrom).Fuel = Locat(Col(intCol).iFrom).Fuel - 2
                                    If Locat(Col(intCol).iFrom).Fuel < 0 Then Locat(Col(intCol).iFrom).Fuel = 0
                                End If
                                For intCount = 1 To intPosTo
                                    ColLoc(ColLoc.Length - 1) = ColLoc(ColLoc.Length - 1) & " @" & PosTo(intCount).strTo
                                Next
                            Else
                                If intBdgOut < 1 Then
                                    With Col(intCol)
                                        Select Case .Side
                                            Case 1
                                                If .iFrom <> RouteStart(2, 1) Then
                                                    ReDim Preserve strDebrief(strDebrief.Length)
                                                    strOutput = "Possible error in road system or bridge may be down " & Col(intCol).Ident & " " & Col(intCol).sFrom
                                                    strDebrief(strDebrief.Length - 1) = strOutput
                                                End If
                                            Case Else
                                                If .iFrom <> RouteStart(1, 1) Then
                                                    ReDim Preserve strDebrief(strDebrief.Length)
                                                    strOutput = "Possible error in road system or bridge may be down " & Col(intCol).Ident & " " & Col(intCol).sFrom
                                                    strDebrief(strDebrief.Length - 1) = strOutput
                                                End If
                                        End Select
                                    End With

                                Else

                                    ReDim Preserve strDebrief(strDebrief.Length)
                                    strOutput = "Bridge down " & Col(intCol).Ident & " " & Col(intCol).sFrom
                                    strDebrief(strDebrief.Length - 1) = strOutput
                                End If


                            End If
                        End If
                        'Find Locations a Column might retreat to
                        If Col(intCol).Side = Locat(Col(intCol).iFrom).Side And _
                                (Locat(Col(intCol).iFrom).Fuel > 1 Or InStr(Col(intCol).Unit, "Infantry") > 0) Then
                            intPosTo = 0
                            Select Case Col(intCol).Side
                                Case 1
                                    For intLoc = 1 To Road.Length - 1
                                        If Road(intLoc).iFrom = Col(intCol).iFrom Then
                                            intCntBdg = 0
                                            If Bridge.Length > 1 And _
                                                Col(intCol).Amp < 1 And _
                                                MissSettings.Bridge > 1 Then
                                                For intCntBdg = Bridge.Length - 1 To 1 Step -1
                                                    If Road(intLoc).strTo = Bridge(intCntBdg).sTo And _
                                                        Road(intLoc).strFrom = Bridge(intCntBdg).sFrom Then
                                                        intBdgOut = intBdgOut + 1
                                                        Exit For
                                                    End If
                                                Next
                                            End If
                                            If intCntBdg < 1 Then
                                                intPosTo = intPosTo + 1
                                                ReDim Preserve PosTo(intPosTo)
                                                PosTo(intPosTo).iTo = Road(intLoc).iTo
                                                PosTo(intPosTo).strTo = Road(intLoc).strTo
                                            End If
                                        End If
                                    Next


                                Case 2
                                    For intLoc = 1 To Road.Length - 1
                                        If Road(intLoc).iTo = Col(intCol).iFrom Then
                                            intCntBdg = 0
                                            If Bridge.Length > 1 And _
                                                Col(intCol).Amp < 1 And _
                                                MissSettings.Bridge > 1 Then
                                                For intCntBdg = Bridge.Length - 1 To 1 Step -1
                                                    If Road(intLoc).strTo = Bridge(intCntBdg).sTo And _
                                                        Road(intLoc).strFrom = Bridge(intCntBdg).sFrom Then
                                                        Exit For
                                                    End If
                                                Next
                                            End If
                                            If intCntBdg < 1 Then
                                                intPosTo = intPosTo + 1
                                                ReDim Preserve PosTo(intPosTo)
                                                PosTo(intPosTo).iTo = Road(intLoc).iFrom
                                                PosTo(intPosTo).strTo = Road(intLoc).strFrom
                                            End If
                                        End If
                                    Next
                            End Select

                            If intPosTo > 0 Then
                                For intCount = 1 To intPosTo
                                    ColLoc(ColLoc.Length - 1) = ColLoc(ColLoc.Length - 1) & " @" & PosTo(intCount).strTo
                                Next
                            End If
                        End If
                    End If
            End Select
        Next
    End Sub


    Public Sub LoadColumns(ByRef bolerror As Boolean, _
                            ByRef strerror As String, _
                            ByRef Col() As Column, _
                            ByRef Locat() As Location, _
                            ByRef Harbor() As Location, _
                            ByRef RouteStart(,) As Integer)
        Dim intCol As Integer
        Dim intTank As Integer
        Dim intRoom As Integer
        'This sub loads tanks onto a train or ship
        For intCol = 1 To Col.Length - 1
            intRoom = 0
            With Col(intCol)
                If .iFrom > 0 Then
                    If .Columns > 0 And Locat(Harbor(.iFrom).intRoad).Side = .Side Then
                        Select Case .Side
                            Case 1
                                If .iFrom <> RouteStart(2, 3) Then
                                    intRoom = .Columns
                                    For intTank = 1 To Col.Length - 1
                                        If Col(intTank).sFrom = .Ident Then
                                            intRoom = intRoom - 1
                                            .Direction = 1
                                        End If
                                    Next
                                    For intTank = 1 To Col.Length - 1
                                        If intRoom < 1 Then Exit For
                                        If Col(intTank).iFrom = Locat(.iFrom).intRoad Then
                                            Col(intTank).sFrom = .Ident
                                            Col(intTank).sTo = .Ident
                                            Col(intTank).iFrom = -1
                                            Col(intTank).iFrom = -1
                                            intRoom = intRoom - 1
                                            .Direction = 1
                                        End If
                                    Next
                                End If
                            Case 2
                                If .iFrom <> RouteStart(1, .Type) Then
                                    intRoom = .Columns
                                    For intTank = 1 To Col.Length - 1
                                        If Col(intTank).sFrom = .Ident Then
                                            intRoom = intRoom - 1
                                            .Direction = 1
                                        End If
                                    Next
                                    For intTank = 1 To Col.Length - 1
                                        If intRoom < 1 Then Exit For
                                        If Col(intTank).iFrom = Locat(.iFrom).intRoad Then
                                            Col(intTank).sFrom = .Ident
                                            Col(intTank).sTo = .Ident
                                            Col(intTank).iFrom = -1
                                            Col(intTank).iFrom = -1
                                            intRoom = intRoom - 1
                                            .Direction = 1
                                        End If
                                    Next
                                End If
                        End Select
                    End If
                End If
            End With
        Next
    End Sub
    Public Sub UpdateSquadrons(ByRef bolerror As Boolean, _
                                ByRef strerror As String, _
                                ByRef BornPlace() As BornPlaceClass, _
                                ByRef camsettings As Campaign, _
                                ByRef Ship() As Column, _
                                ByRef Locat() As Location, _
                                ByRef Squad() As Squad_Type, _
                                ByRef INI_Settings As INI_Class)
        Dim iSquad As Integer
        Dim iBP As Integer
        Dim iRedBase As Integer
        Dim iBlueBase As Integer
        If Squad.Length < 2 Then
            bolerror = True
            strerror = "No Squads found in -UpdateSquadrons-"
        End If
        'Find Red HomeBase
        If camsettings.RuHome <> "" Then
            For iRedBase = Locat.Length - 1 To 1 Step -1
                If Locat(iRedBase).Loc = camsettings.RuHome Then Exit For
            Next
        End If
        If camsettings.DeHome <> "" Then
            For iBlueBase = Locat.Length - 1 To 1 Step -1
                If Locat(iBlueBase).Loc = camsettings.DeHome Then Exit For
            Next
        End If
        For iSquad = 1 To Squad.Length - 1
            With Squad(iSquad)
                .Number = .Number + INI_Settings.ACSupply
                If .Number > .Max Then .Number = .Max
                If .Number < .Min Then .Number = .Min
                If .iLoc > 0 Then
                    If .Side <> Locat(.iLoc).Side Then
                        If .Side = 1 Then
                            .Loc = camsettings.RuHome
                            .iLoc = iRedBase
                        Else
                            .Loc = camsettings.DeHome
                            .iLoc = iBlueBase
                        End If
                    End If
                Else
                    If Ship(.iLoc * -1).Carrier > 0 Then
                        If Ship(.iLoc * -1).Carrier > Ship(.iLoc * -1).Curr Or _
                            Ship(.iLoc * -1).iFrom < 1 Then
                            If .Side = 1 Then
                                .Loc = camsettings.RuHome
                                .iLoc = iRedBase
                            Else
                                .Loc = camsettings.DeHome
                                .iLoc = iBlueBase
                            End If
                        End If
                    Else
                        If .Side = 1 Then
                            .Loc = camsettings.RuHome
                            .iLoc = iRedBase
                        Else
                            .Loc = camsettings.DeHome
                            .iLoc = iBlueBase
                        End If
                    End If
                End If
            End With

        Next
        'set bornplaces with AC to active
        For iBP = 1 To BornPlace.Length - 1
            With BornPlace(iBP)
                .Active = False
                For iSquad = 1 To Squad.Length - 1
                    If Squad(iSquad).Loc = .Loc Then .Active = True
                Next
            End With
        Next
    End Sub

    Public Sub GenMission(ByRef bolerror As Boolean, _
                            ByRef strerror As String, _
                            ByRef MisWeather As Integer, _
                            ByRef MisCloud As Integer, _
                            ByRef sMissFolder As String, _
                            ByRef Wind As Weather, _
                            ByRef House() As String, _
                            ByRef BornPlace() As BornPlaceClass, _
                            ByRef ConvoyVeh(,) As String, _
                            ByRef convoyinfo() As Convoy, _
                            ByRef StructInfo() As Building, _
                            ByRef StructList(,) As String, _
                            ByRef Fact() As Factory, _
                            ByRef Rocket() As RocketType, _
                            ByRef CamSettings As Campaign, _
                            ByRef MissSettings As Mission, _
                            ByRef Stat() As Stationary, _
                            ByRef Col() As Column, _
                            ByRef Ship() As Column, _
                            ByRef Train() As Column, _
                            ByRef Infantry() As Column, _
                            ByRef Locat() As Location, _
                            ByRef Station() As Location, _
                            ByRef Harbor() As Location, _
                            ByRef Road() As Waypoint, _
                            ByRef ShipRoute() As Waypoint, _
                            ByRef Rail() As Waypoint, _
                            ByRef Trail() As Waypoint, _
                            ByRef Bldg() As Stationary, _
                            ByRef Chief() As String, _
                            ByRef ChiefMov() As String, _
                            ByRef ChiefRd() As String, _
                            ByRef DeadBridge() As String, _
                            ByRef RoadWp() As String, _
                            ByRef RailWP() As String, _
                            ByRef SeaWP() As WP, _
                            ByRef TrailWP() As String, _
                            ByRef Squad() As Squad_Type, _
                            ByRef UseSquad As Integer, _
                            ByRef MDS() As String, _
                            ByRef MODS() As String, _
                            ByRef Radar() As Factory, _
                            ByRef RedCountry() As String, _
                            ByRef BlueCountry() As String, _
                            ByRef INI_Settings As INI_Class, _
                            ByRef MisTime As Single, _
                            ByRef Manufacture() As Factory)

        Dim strOutput As String
        Dim intUnit As Integer
        Dim intCount As Integer
        Dim intCount2 As Integer
        Dim XRand As Double
        Dim YRand As Double
        Dim i As Integer
        Dim DF(0) As String
        Dim iDF As Integer
        Dim sb As StringBuilder
        Dim iShipOffSet As Integer = 1
        sb = New StringBuilder
        'Main section    
        sb.AppendLine("[MAIN]")

        If InStr(camsettings.Map, ".ini") < 1 Then
            sb.AppendLine("  MAP " & camsettings.Map & "/load.ini")
        Else
            sb.AppendLine("  MAP " & camsettings.Map)
        End If
        If MisTime < 1 Then SetConditions(MisTime, _
                                            MisWeather, _
                                            MisCloud, _
                                            Wind, _
                                            MissSettings)
        'Time
        sb.AppendLine("  TIME " & Format(MisTime, "0.00"))


        'Weather
        sb.AppendLine("  CloudType " & Format(MisWeather, "0"))
        'CloudHeight    
        sb.AppendLine("  CloudHeight " & Format(MisCloud, "###0"))
        'SEASON
        sb.AppendLine("[SEASON]")
        sb.AppendLine("  Year " & Format(camsettings.dDate, "yyyy"))
        sb.AppendLine("  Month " & Format(CamSettings.dDate, "MM"))
        sb.AppendLine("  Day " & Format(CamSettings.dDate, "dd"))
        'WEATHER SECTION
        sb.AppendLine("[WEATHER]")
        sb.AppendLine("  WindDirection " & Format(Wind.Direction, "0.0"))
        sb.AppendLine("  WindSpeed " & Format(Wind.Velocity, "0.0"))
        sb.AppendLine("  Gust " & Format(Wind.Gust, "0"))
        sb.AppendLine("  Turbulence " & Format(Wind.Turbulence, "0"))
        'MODS Section
        If MODS.Length > 1 Then
            For i = 1 To MODS.Length - 1
                sb.AppendLine(MODS(i))
            Next
        End If
        'Wing
        sb.AppendLine("[WING]")
        'CHIEFS SECTION
        sb.AppendLine("[Chiefs]")
        'Vehicles
        For intCount = 1 To Col.Length - 1
            With Col(intCount)
                If .iFrom > 0 Then
                    If InStr(.Unit, "Armor.") > 0 Then
                        PlaceTank(intCount, _
                                    MissSettings, _
                                    Col, _
                                    Locat, _
                                    Road, _
                                    Chief, _
                                    ChiefMov, _
                                    ChiefRd, _
                                    RoadWp, _
                                    INI_Settings, _
                                    camsettings)
                    Else 'Car Column
                        If .ConType > 0 Then
                            If .Artillery > 0 Then
                                PlaceArtillery(intCount, _
                                                ConvoyVeh, _
                                                Col, _
                                                Locat, _
                                                Road, _
                                                Chief, _
                                                INI_Settings)
                            Else
                                PlaceColumn(intCount, _
                                            ConvoyVeh, _
                                            convoyinfo, _
                                            MissSettings, _
                                            Col, _
                                            Locat, _
                                            Road, _
                                            Chief, _
                                            ChiefMov, _
                                            ChiefRd, _
                                            RoadWp, _
                                            INI_Settings, _
                                            camsettings)
                            End If
                        Else
                            PlaceCar(intCount, _
                                     convoyinfo, _
                                     MissSettings, _
                                     Col, _
                                     Locat, _
                                     Road, _
                                     Chief, _
                                     ChiefMov, _
                                     ChiefRd, _
                                     RoadWp, _
                                     INI_Settings)
                        End If
                    End If

                End If
            End With
        Next

        'Infantry
        For intCount = 1 To Infantry.Length - 1
            With Infantry(intCount)
                If .iFrom > 0 Then
                    PlaceInfantry(intCount, _
                                  MissSettings, _
                                  Infantry, _
                                  Locat, _
                                  Trail, _
                                  Chief, _
                                  ChiefMov, _
                                  ChiefRd, _
                                  TrailWP, _
                                  INI_Settings, _
                                  camsettings)

                End If
            End With
        Next

        'TRAINS
        For intCount = 1 To Train.Length - 1
            With Train(intCount)
                If .iFrom > 0 Then
                    PlaceTrain(intCount, _
                               ConvoyVeh, _
                               MissSettings, _
                               Train, _
                               Station, _
                               Rail, _
                               Chief, _
                               ChiefMov, _
                               ChiefRd, _
                               RailWP, _
                               INI_Settings)
                End If
            End With
        Next
        'SHIPS
        For intCount = 1 To Ship.Length - 1
            With Ship(intCount)
                If .iFrom > 0 Then
                    PlaceShip(intCount, _
                              BornPlace, _
                              ConvoyVeh, _
                              MissSettings, _
                              Ship, _
                              Harbor, _
                              ShipRoute, _
                              Chief, _
                              ChiefMov, _
                              ChiefRd, _
                              SeaWP, _
                              INI_Settings, _
                              iShipOffSet)
                End If
            End With
        Next
        'Add moving chiefs to the mission file
        If ChiefMov.Length > 1 Then
            For i = 1 To ChiefMov.Length - 1
                sb.AppendLine(ChiefMov(i))
            Next
            For i = 1 To ChiefRd.Length - 1
                sb.AppendLine(ChiefRd(i))
            Next
        End If
        'CHIEFS SECTION END
        sb.AppendLine("[Stationary]")
        sb.AppendLine("[NStationary]")
        'STATIC SECTION
        For intCount = 1 To Stat.Length - 1
            With Stat(intCount)
                If InStr(.Unit, ".planes.Plane$") > 0 Then
                    strOutput = ""
                    PlaceGndAircraft(Stat(intCount), _
                                     Locat, _
                                     Squad, _
                                     strOutput)
                    If strOutput <> "" Then sb.AppendLine(strOutput)
                Else
                    If Stat(intCount).Active Then
                        strOutput = "  " & _
                                    .Ident & " " & _
                                    .Unit & " " & _
                                    Format(.Side, "0") & " " & _
                                    Format(.X, "########0.00") & " " & _
                                    Format(.Y, "########0.00") & " " & _
                                    Format(.Head, "##0.00") & " " & _
                                    .Other
                        sb.AppendLine(strOutput)
                    End If
                End If
            End With
        Next
        'ADD STATIC CHIEFs SECTION
        If Chief.Length > 1 Then
            For i = 1 To Chief.Length - 1
                sb.AppendLine(Chief(i))
            Next
        End If
        'END CHIEF STATIC SECTION

        'FACTORY STATIONARY SECTION
        If Fact.Length > 1 Then
            For intCount = 1 To Fact.Length - 1
                With Fact(intCount)
                    If .Struct > 0 Then PlaceFactStat(intCount, sb, _
                                                        StructInfo, _
                                                        StructList, _
                                                        Fact)
                End With
            Next
        End If
        'END FACTORY STATIONARY SECTION

        'FACTORY PLATE SECTION
        If Manufacture.Length > 1 Then
            For intCount = 1 To Manufacture.Length - 1
                With Manufacture(intCount)
                    strOutput = "  " & _
                                    .ID & " " & _
                                    .Unit & " " & _
                                    Format(.Side, "0") & " " & _
                                    Format(.X, "0.00") & " " & _
                                    Format(.Y, "0.00") & " " & _
                                    Format(.Head, "0.00") & " " & _
                                    .Other
                    sb.AppendLine(strOutput)
                End With
            Next
        End If
        'END FACTORY PLATE SECTION

        'RADAR STATIONARY SECTION
        If Radar.Length > 1 Then
            For intCount = 1 To Radar.Length - 1
                With Radar(intCount)
                    If .Struct > 0 Then PlaceRadarStat(intCount, _
                                                        sb, _
                                                        StructList, _
                                                        Radar)
                End With
            Next
        End If
        'END FACTORY STATIONARY SECTION

        'Rocket Stationary Section
        If Rocket.Length > 1 Then
            For intCount = 1 To Rocket.Length - 1
                With Rocket(intCount)
                    If .ConType > 0 Then PlaceRocketStat(intCount, _
                                                            sb, _
                                                            ConvoyVeh, _
                                                            Rocket)
                End With
            Next
        End If
        'ROCKET SECTION
        sb.AppendLine("[Rocket]")
        If Rocket.Length > 1 Then

            For intCount = 1 To Rocket.Length - 1
                If Rocket(intCount).Active Then
                    XRand = (Rnd() * 5000) - 2500
                    YRand = (Rnd() * 5000) - 2500
                    With Rocket(intCount)
                        strOutput = "  " & _
                                .Ident & " " & _
                                .Unit & " " & _
                                Format(.Side, "0") & " " & _
                                Format(.X, "0.00") & " " & _
                                Format(.Y, "0.00") & " " & _
                                Format(.Head, "0.00") & " " & _
                                Format(.Time, "0.0") & " " & _
                                Format(.Num, "0") & " " & _
                                Format(.Interval, "0.0") & " " & _
                                Format(.Xtgt + XRand, "0.00") & " " & _
                                Format(.Ytgt + YRand, "0.00")
                    End With
                    sb.AppendLine(strOutput)
                End If
            Next
        End If

        'BUILDING SECTION
        sb.AppendLine("[Buildings]")
        For intCount = 1 To Bldg.Length - 1
            If Bldg(intCount).Active Then
                With Bldg(intCount)
                    strOutput = "  " & _
                                .Ident & " " & _
                                .Unit & " " & _
                                Format(.Side, "0") & " " & _
                                Format(.X, "########0.00") & " " & _
                                Format(.Y, "########0.00") & " " & _
                                Format(.Head, "##0.00")
                End With
                sb.AppendLine(strOutput)
            End If
        Next
        'FACTORY BUILDING SECTION
        For intCount = 1 To Fact.Length - 1
            With Fact(intCount)
                strOutput = "  " & _
                        .ID & "0 " & _
                        .Unit & " "

                If Fact(intCount).Active Then
                    strOutput = strOutput & "1 "
                Else
                    If INI_Settings.intShowDestFact > 0 Then
                        strOutput = strOutput & "0 "
                    Else
                        strOutput = ""
                    End If
                End If
                If strOutput <> "" Then
                    strOutput = strOutput & _
                        Format(.X, "0.00") & " " & _
                        Format(.Y, "0.00") & " " & _
                        Format(.Head, "0.00")
                    sb.AppendLine(strOutput)
                End If
            End With
        Next

        'RADAR BUILDING SECTION
        If Radar.Length > 1 Then
            For intCount = 1 To Radar.Length - 1
                With Radar(intCount)
                    strOutput = "  " & _
                            .ID & "0 " & _
                            .Unit & " "
                    If .Active Then
                        strOutput = strOutput & "1 " & _
                            Format(.X, "0.00") & " " & _
                            Format(.Y, "0.00") & " " & _
                            Format(.Head, "0.00")
                        sb.AppendLine(strOutput)
                    Else
                        strOutput = ""
                    End If
                End With
            Next
        End If
        'TARGET SECTION
        sb.AppendLine("[Target]")
        'CAMERA SECTION
        sb.AppendLine("[StaticCamera]")
        'BORNPLACE SECTION
        sb.AppendLine("[BornPlace]")

        'Use the Aircraft File
        Dim sBP(0) As String
        Dim iBP As Integer
        Dim iAC As Integer
        intUnit = 0
        For intCount = 1 To BornPlace.Length - 1
            With BornPlace(intCount)
                If .Side > 0 And .Active Then
                    strOutput = "  " & Format(.Side, "0") & _
                            " " & Format(.R, "0") & _
                            " " & Format(.X, "0") & _
                            " " & Format(.Y, "0")
                    If .Side = 1 And MissSettings.RedRadar <> "" Then strOutput = strOutput & " " & MissSettings.RedRadar
                    If .Side = 2 And MissSettings.BlueRadar <> "" Then strOutput = strOutput & " " & MissSettings.BlueRadar
                    sb.AppendLine(strOutput)
                    iBP = iBP + 1
                    ReDim Preserve sBP(iBP)
                    sBP(iBP) = "[BornPlace" & Format(intUnit, "0") & "]"
                    For iAC = 1 To Squad.Length - 1
                        If Squad(iAC).Loc = .Loc Then
                            iBP = iBP + 1
                            ReDim Preserve sBP(iBP)
                            If Squad(iAC).Suppressed > 0 Then
                                sBP(iBP) = "  " & Squad(iAC).DF & "-1 0"
                            Else
                                sBP(iBP) = "  " & Squad(iAC).DF & " " & Squad(iAC).WeaponsDF
                            End If

                        End If
                    Next
                    'how it was
                    '[BornPlaceCountries7]()
                    'us()
                    'gb()
                    '[BornPlace8]()
                    'how it needs to be
                    '[MDS_BornPlace_292300_168700_Countries]()
                    'us()
                    'gb()
                    '[BornPlace12]()
                    If .Side = 1 And RedCountry.Length > 1 Then
                        iBP = iBP + 1
                        ReDim Preserve sBP(iBP)
                        sBP(iBP) = "[MDS_BornPlace_" & _
                                            Format(.X, "0") & "_" & _
                                            Format(.Y, "0") & "_Countries" & "]"

                        For iDF = 1 To RedCountry.Length - 1
                            iBP = iBP + 1
                            ReDim Preserve sBP(iBP)
                            sBP(iBP) = "  " & RedCountry(iDF)
                        Next
                    End If
                    If .Side = 2 And BlueCountry.Length > 1 Then
                        iBP = iBP + 1
                        ReDim Preserve sBP(iBP)
                        sBP(iBP) = "[MDS_BornPlace_" & _
                                            Format(.X, "0") & "_" & _
                                            Format(.Y, "0") & "_Countries" & "]"
                        For iDF = 1 To BlueCountry.Length - 1
                            iBP = iBP + 1
                            ReDim Preserve sBP(iBP)
                            sBP(iBP) = "  " & BlueCountry(iDF)
                        Next
                    End If
                    intUnit = intUnit + 1
                End If
            End With
        Next
        For intCount = 1 To iBP
            sb.AppendLine(sBP(intCount))
        Next
        'RESPAWN SECTION
        sb.AppendLine("[RespawnTime]")
        strOutput = "  Bigship " & Format(INI_Settings.MisLength * 60000, "0")
        sb.AppendLine(strOutput)
        strOutput = "  Ship " & Format(INI_Settings.MisLength * 60000, "0")
        sb.AppendLine(strOutput)
        strOutput = "  Aeroanchored " & Format(INI_Settings.MisLength * 60000, "0")
        sb.AppendLine(strOutput)
        strOutput = "  Artillery " & Format(INI_Settings.MisLength * 60000, "0")
        sb.AppendLine(strOutput)
        strOutput = "  Searchlight " & Format(INI_Settings.MisLength * 60000, "0")
        sb.AppendLine(strOutput)
        'BRIDGE SECTION
        sb.AppendLine("[Bridge]")
        LoadDeadBridge(DeadBridge, _
                       INI_Settings)
        If DeadBridge.Length > 1 Then
            For intCount = 1 To DeadBridge.Length - 1
                strOutput = "  " & DeadBridge(intCount)
                sb.AppendLine(strOutput)
            Next
        End If
        'HOUSE SECTION
        sb.AppendLine("[House]")
        If House.Length > 1 Then
            For intCount = 1 To House.Length - 1
                strOutput = "  " & House(intCount)
                sb.AppendLine(strOutput)
            Next
        End If
        'FRONTLINE section
        sb.AppendLine("[FrontMarker]")
        For intCount = 1 To Locat.Length - 1
            With Locat(intCount)
                If .Type < 3 Then
                    If .Side > 0 Then
                        strOutput = "  FrontMarker" & Format(intCount - 1, "####0") & " " & _
                                    Format(.X, "########0.00") & " " & _
                                    Format(.Y, "########0.00") & " " & _
                                    Format(.Side, "0")
                    End If
                    sb.AppendLine(strOutput)
                End If
            End With
        Next
        If Harbor.Length > 1 Then
            For intCount2 = 1 To Harbor.Length - 1
                With Harbor(intCount2)

                    If .Side > 0 Then
                        strOutput = "  FrontMarker" & Format(intCount2 + intCount - 2, "####0") & " " & _
                                    Format(.X, "########0.00") & " " & _
                                    Format(.Y, "########0.00") & " " & _
                                    Format(.Side, "0")
                    End If
                    sb.AppendLine(strOutput)
                End With
            Next
        End If
        'MDS Section
        If MDS.Length > 1 Then
            For i = 1 To MDS.Length - 1
                sb.AppendLine(MDS(i))
            Next
        End If
        'Using outfile As New StreamWriter(sMissFolder & "/dcgmission.mis")
        'outfile.Write(sb.ToString())
        'outfile.Close()
        'End Using
        FileOpen(1, sMissFolder & "/dcgmission.mis", OpenMode.Output, OpenAccess.Write, OpenShare.Shared)
        Print(1, sb.ToString)
        FileClose(1)
    End Sub

    Public Sub GenFiles(ByRef bolerror As Boolean, _
                        ByRef strerror As String, _
                        ByRef sEventDate As String, _
                        ByRef ColLoc() As String, _
                        ByRef MisWeather As Integer, _
                        ByRef MisCloud As Integer, _
                        ByRef wind As Weather, _
                        ByRef Bridge() As Brid, _
                        ByRef Fact() As Factory, _
                        ByRef Rocket() As RocketType, _
                        ByRef camsettings As Campaign, _
                        ByRef MissSettings As Mission, _
                        ByRef Stat() As Stationary, _
                        ByRef Col() As Column, _
                        ByRef Ship() As Column, _
                        ByRef Train() As Column, _
                        ByRef Infantry() As Column, _
                        ByRef Locat() As Location, _
                        ByRef Station() As Location, _
                        ByRef Harbor() As Location, _
                        ByRef strDebrief() As String, _
                        ByRef strFrontLine() As String, _
                        ByRef strACMove() As String, _
                        ByRef strBdgDown() As String, _
                        ByRef AC_New() As AC_Type, _
                        ByRef Squad() As Squad_Type, _
                        ByRef UseSquad As Integer, _
                        ByRef SupplyAC() As AC_Supply, _
                        ByRef Radar() As Factory, _
                        ByRef RedCountry() As String, _
                        ByRef BlueCountry() As String, _
                        ByRef INI_Settings As INI_Class, _
                        ByRef MisTime As Single, _
                        ByRef Manufacture() As Factory)
        BackupCampaign(bolerror, _
                       strerror, _
                       camsettings, _
                       INI_Settings)
        If bolerror Then Exit Sub
        GenColumnFile(bolerror, _
                      strerror, _
                      Col, _
                      Ship, _
                      Train, _
                      Infantry, _
                      INI_Settings)
        If bolerror Then Exit Sub
        GenColLocFile(bolerror, _
                      strerror, _
                      ColLoc, _
                      INI_Settings)
        If bolerror Then Exit Sub
        GenStatFile(bolerror, _
                    strerror, _
                    Stat, _
                    INI_Settings)
        If bolerror Then Exit Sub
        GenRocketFile(bolerror, _
                      strerror, _
                      Rocket, _
                      INI_Settings)
        If bolerror Then Exit Sub
        GenBridgeFile(bolerror, _
                      strerror, _
                      Bridge, _
                      MissSettings, _
                      INI_Settings)
        If bolerror Then Exit Sub
        GenTerrFile(bolerror, _
                    strerror, _
                    Locat, _
                    Station, _
                    Harbor, _
                    INI_Settings)
        If bolerror Then Exit Sub
        'GenLocFile( bolerror, strerror)
        'If bolError Then Exit Sub

        GenAircraftFile(AC_New, _
                        Squad, _
                        INI_Settings)
        GenCampFile(bolerror, _
                    strerror, _
                    camsettings, _
                    MissSettings, _
                    SupplyAC, _
                    RedCountry, _
                    BlueCountry, _
                    INI_Settings)
        If bolerror Then Exit Sub
        GenFactFile(bolerror, _
                    strerror, _
                    Fact, _
                    INI_Settings)
        If manufacture.length > 1 Then GenPlateFile(Manufacture, _
                                                    INI_Settings)
        If bolerror Then Exit Sub
        GenRadarFile(Radar, _
                     INI_Settings)

        GenConditionsFile(MisTime, _
                          MisWeather, _
                            MisCloud, _
                            wind, _
                            INI_Settings)
        SaveDebriefs(strDebrief, _
                     strFrontLine, _
                     strACMove, _
                     strBdgDown, _
                     INI_Settings)
    End Sub

    Public Sub GndAircraft(ByRef bolerror As Boolean, _
                            ByRef strerror As String, _
                            ByRef Stat() As Stationary, _
                            ByRef Locat() As Location, _
                            ByRef Squad() As Squad_Type)
        Dim intCntSqd As Integer
        Dim intCntStat As Integer
        Dim intACTypes As Integer
        Dim intACRnd As Integer
        Dim ACTypes(0) As String
        For intCntStat = 1 To Stat.Length - 1
            With Stat(intCntStat)
                If InStr(.Unit, ".planes.Plane$") > 0 Then
                    If .Side = Locat(.intLoc).Side Then
                        intACTypes = 0
                        For intCntSqd = 1 To Squad.Length - 1
                            If Squad(intCntSqd).iLoc = .intLoc And Squad(intCntSqd).Number > 0 Then
                                intACTypes = intACTypes + 1
                                ReDim Preserve ACTypes(intACTypes)
                                ACTypes(intACTypes) = Squad(intCntSqd).Coop
                            End If
                        Next
                        If intACTypes > 0 Then
                            intACRnd = Int((Rnd() * intACTypes) + 1)
                            .Unit = "vehicles.planes.Plane$" & ACTypes(intACRnd)
                            .Active = True
                        Else
                            .Active = False
                        End If
                    Else
                        .Active = False
                    End If
                End If
            End With
        Next
    End Sub
    Public Sub PlaceGndAircraft(ByRef Stat As Stationary, _
                            ByRef Locat() As Location, _
                            ByRef Squad() As Squad_Type, _
                            ByRef sLine As String)
        Dim intCntSqd As Integer
        Dim intACTypes As Integer
        Dim intACRnd As Integer
        Dim ACTypes(0) As String
        Dim ACCountry(0) As String
        With Stat
            If InStr(.Unit, ".planes.Plane$") > 0 Then
                If .Side = Locat(.intLoc).Side Then
                    intACTypes = 0
                    For intCntSqd = 1 To Squad.Length - 1
                        If Squad(intCntSqd).iLoc = .intLoc And Squad(intCntSqd).Number > 0 Then
                            intACTypes = intACTypes + 1
                            ReDim Preserve ACTypes(intACTypes)
                            ReDim Preserve ACCountry(intACTypes)
                            ACTypes(intACTypes) = Squad(intCntSqd).Coop
                            ACCountry(intACTypes) = Squad(intCntSqd).country
                        End If
                    Next
                    If intACTypes > 0 Then
                        intACRnd = Int((Rnd() * intACTypes) + 1)
                        .Unit = "vehicles.planes.Plane$" & ACTypes(intACRnd)
                        .Active = True
                        sLine = "  " & _
                                    .Ident & " " & _
                                    .Unit & " " & _
                                    Format(.Side, "0") & " " & _
                                    Format(.X, "########0.00") & " " & _
                                    Format(.Y, "########0.00") & " " & _
                                    Format(.Head, "##0.00") & " " & _
                                    .Other
                        sLine = Replace(sLine, "null", ACCountry(intACRnd))
                    Else
                        .Active = False
                    End If
                Else
                    .Active = False
                End If
            End If
        End With
    End Sub
    Public Sub MoveCoor(ByRef dbX As Double, _
                     ByRef dbY As Double, _
                    ByRef Head As Integer, _
                    ByRef intDist As Integer)
        Dim X As Double
        Dim Y As Double
        Do
            If Head >= 0 Or Head <= 360 Then Exit Do
            If Head > 360 Then Head = Head - 360
            If Head < 0 Then Head = Head + 360
        Loop

        Y = Math.Cos(Head * 3.14 / 180) * intDist
        X = Math.Sin(Head * 3.14 / 180) * intDist
        dbX = dbX + X
        dbY = dbY + Y
    End Sub
    Public Sub LoadBornPlaceFile(ByRef bolerror As Boolean, _
                            ByRef strerror As String, _
                            ByRef BornPlace() As BornPlaceClass, _
                            ByRef camsettings As Campaign, _
                            ByRef Locat() As Location, _
                            ByRef ini_settings As INI_Class)

        Dim strBornFile As String
        Dim strInput As String
        Dim intStart As Integer
        Dim sTemp As String
        Dim filereader As IO.StreamReader
        strBornFile = ini_settings.sData & camsettings.RouteName & ".bpl"
        If Dir(strBornFile) = "" Then
            bolerror = True
            strerror = "Cannot find BornPlace file!"
            Exit Sub
        End If
        If My.Computer.FileSystem.FileExists(strBornFile) Then
            filereader = My.Computer.FileSystem.OpenTextFileReader(strBornFile)
            Do Until filereader.EndOfStream
                strInput = filereader.ReadLine
                intStart = InStr(strInput, "[")
                If strInput <> "" And intStart = 0 Then
                    ReDim Preserve BornPlace(BornPlace.Length)
                    strInput = Trim(strInput)
                    With BornPlace(BornPlace.Length - 1)
                        intStart = InStr(strInput, " ")
                        If intStart > 0 Then
                            .X = Int(Val(Left(strInput, intStart)))
                            sTemp = Trim(Mid(strInput, intStart))
                            intStart = InStr(sTemp, " ")
                            If intStart > 0 Then
                                .Y = Int(Val(Left(sTemp, intStart)))
                                .R = Int(Val(Mid(sTemp, intStart)))
                            Else
                                .Y = Int(Val(sTemp))
                                .R = Int(ini_settings.BornPlaceRadius)
                            End If
                            FindWayPoint(.X, _
                                         .Y, _
                                         .Loc, _
                                        .intLoc, _
                                        Locat)
                            .Side = Locat(.intLoc).Side
                            If InStr(.Loc, "_Seaplane_Base") > 0 Then .Type = 2
                        Else
                            bolerror = True
                            strerror = "Error in BornPlace file!"
                            Exit Do
                        End If
                    End With
                End If
            Loop
            filereader.Close()
        End If
    End Sub
    Public Sub PlaceShip(ByRef intChief As Integer, _
                            ByRef BornPlace() As BornPlaceClass, _
                            ByRef ConvoyVeh(,) As String, _
                            ByRef MissSettings As Mission, _
                            ByRef Ship() As Column, _
                            ByRef Harbor() As Location, _
                            ByRef ShipRoute() As Waypoint, _
                            ByRef Chief() As String, _
                            ByRef ChiefMov() As String, _
                            ByRef ChiefRd() As String, _
                            ByRef SeaWP() As WP, _
                            ByRef INI_Settings As INI_Class, _
                            ByRef iShipOffSet As Integer)
        Dim intUnit As Integer
        Dim dbX As Double
        Dim dbY As Double
        Dim intHead As Integer
        Dim strUnit As String = ""
        Dim intRd As Integer
        Dim iBP As Integer
        Dim strOutput As String = ""
        With Ship(intChief)
            If .iFrom = .iTo Then 'Ship at a named location
                If .ConType > 0 Then
                    If .Side = 1 Then

                        dbX = Harbor(.iFrom).AlliedX
                        dbY = Harbor(.iFrom).AlliedY
                        intHead = Harbor(.iFrom).AlliedH
                        MoveCoor(Harbor(.iFrom).AlliedX, _
                                Harbor(.iFrom).AlliedY, _
                                Harbor(.iFrom).AlliedH, _
                                (300 * (.Size + 1)))
                    Else

                        dbX = Harbor(.iFrom).AxisX
                        dbY = Harbor(.iFrom).AxisY
                        intHead = Harbor(.iFrom).AxisH
                        MoveCoor(Harbor(.iFrom).AxisX, _
                                Harbor(.iFrom).AxisY, _
                                Harbor(.iFrom).AxisH, _
                                (300 * (.Size + 1)))
                    End If
                    For intUnit = 1 To .Curr
                        If intUnit = .Carrier Then
                            For iBP = 1 To BornPlace.Length - 1
                                If BornPlace(iBP).intLoc = intChief * -1 Then
                                    BornPlace(iBP).Active = True
                                    BornPlace(iBP).X = dbX
                                    BornPlace(iBP).Y = dbY
                                End If
                            Next
                        End If
                        strOutput = "  " & .Ident & Format(intUnit - 1, "0") & _
                            " " & ConvoyVeh(intUnit, .ConType) & _
                            " " & Format(.Side, "0") & _
                            " " & Format(dbX, "########.00") & _
                            " " & Format(dbY, "########.00") & _
                            " " & Format(intHead + 90, "##0.0") & _
                            " 0.0" & _
                            " " & .ROF
                        MoveShipCoor(dbX, _
                            dbY, _
                            intHead, _
                            300)
                        ReDim Preserve Chief(Chief.Length)
                        Chief(Chief.Length - 1) = strOutput
                    Next
                Else 'Single Ship at named location
                    If .Side = 1 Then

                        MoveCoor(Harbor(.iFrom).AlliedX, _
                                Harbor(.iFrom).AlliedY, _
                                Harbor(.iFrom).AlliedH, _
                                600)
                        dbX = Harbor(.iFrom).AlliedX
                        dbY = Harbor(.iFrom).AlliedY
                        intHead = Harbor(.iFrom).AlliedH + 5
                    Else

                        MoveCoor(Harbor(.iFrom).AxisX, _
                                Harbor(.iFrom).AxisY, _
                                Harbor(.iFrom).AxisH, _
                                600)
                        dbX = Harbor(.iFrom).AxisX
                        dbY = Harbor(.iFrom).AxisY
                        intHead = Harbor(.iFrom).AxisH - 5
                    End If

                    If InStr(.Unit, "Ships.") > 0 Then strUnit = Replace(.Unit, "Ships.", "ships.Ship$")
                    If InStr(.Unit, "ShipPack.") > 0 Then strUnit = Replace(.Unit, "ShipPack.", "ships.Ship$")
                    strOutput = "  " & .Ident & _
                                " " & strUnit & _
                                " " & Format(.Side, "0") & _
                                " " & Format(dbX, "0.00") & _
                                " " & Format(dbY, "0.00") & _
                                " " & Format(intHead + 90, "0.0") & _
                                " 0.0" & _
                                " " & .ROF
                    ReDim Preserve Chief(Chief.Length)
                    Chief(Chief.Length - 1) = strOutput

                End If
            Else 'Ship between named locations

                For intRd = ShipRoute.Length - 1 To 1 Step -1
                    If (ShipRoute(intRd).iFrom = .iTo And _
                                ShipRoute(intRd).iTo = .iFrom) Or _
                                (ShipRoute(intRd).iFrom = .iFrom And _
                                ShipRoute(intRd).iTo = .iTo) Then

                        Exit For
                    End If
                Next

                If intRd > 0 Then 'Ships between named locations
                    If .ConType > 0 Then
                        'Ship Convoy
                        If INI_Settings.iMovingDF > 0 Then
                            'Moving ships
                            PlaceShipConvoyMoving(intChief, _
                                                  intRd, _
                                                  BornPlace, _
                                                  ConvoyVeh, _
                                                  MissSettings, _
                                                  Ship, _
                                                  ShipRoute, _
                                                  ChiefMov, _
                                                  ChiefRd, _
                                                  SeaWP, _
                                                  INI_Settings, _
                                                  iShipOffSet)
                        Else
                            If .Side = 1 Then
                                dbX = ShipRoute(intRd).AlliedX
                                dbY = ShipRoute(intRd).AlliedY
                                intHead = ShipRoute(intRd).AlliedH
                                MoveCoor(ShipRoute(intRd).AlliedX, _
                                        ShipRoute(intRd).AlliedY, _
                                        ShipRoute(intRd).AlliedH, _
                                        (300 * (.Size + 1)))
                            Else
                                dbX = ShipRoute(intRd).AxisX
                                dbY = ShipRoute(intRd).AxisY
                                intHead = ShipRoute(intRd).AxisH
                                MoveCoor(ShipRoute(intRd).AxisX, _
                                        ShipRoute(intRd).AxisY, _
                                        ShipRoute(intRd).AxisH, _
                                        (300 * (.Size + 1)))
                            End If
                            For intUnit = 1 To .Curr
                                If intUnit = .Carrier Then
                                    For iBP = 1 To BornPlace.Length - 1
                                        If BornPlace(iBP).intLoc = intChief * -1 Then
                                            BornPlace(iBP).Active = True
                                            BornPlace(iBP).X = dbX
                                            BornPlace(iBP).Y = dbY
                                        End If
                                    Next
                                End If
                                strOutput = "  " & .Ident & Format(intUnit - 1, "0") & _
                                        " " & ConvoyVeh(intUnit, .ConType) & _
                                        " " & Format(.Side, "0") & _
                                        " " & Format(dbX, "0.00") & _
                                        " " & Format(dbY, "0.00") & _
                                        " " & Format(intHead + 90, "0.0") & _
                                        " 0.0" & _
                                        " " & .ROF
                                MoveShipCoor(dbX, _
                                        dbY, _
                                        intHead, _
                                        300)

                                ReDim Preserve Chief(Chief.Length)
                                Chief(Chief.Length - 1) = strOutput
                            Next
                        End If
                    Else 'Single ship between locations
                        If INI_Settings.iMovingDF > 0 Then
                            PlaceShipMoving(intChief, _
                                            intRd, _
                                            MissSettings, _
                                            Ship, _
                                            ShipRoute, _
                                            ChiefMov, _
                                            ChiefRd, _
                                            SeaWP, _
                                            INI_Settings, _
                                            iShipOffSet)
                        Else
                            If .Side = 1 Then
                                dbX = ShipRoute(intRd).AlliedX
                                dbY = ShipRoute(intRd).AlliedY
                                intHead = ShipRoute(intRd).AlliedH + 5
                                MoveCoor(ShipRoute(intRd).AlliedX, _
                                        ShipRoute(intRd).AlliedY, _
                                        ShipRoute(intRd).AlliedH, _
                                        600)
                            Else
                                dbX = ShipRoute(intRd).AxisX
                                dbY = ShipRoute(intRd).AxisY
                                intHead = ShipRoute(intRd).AxisH - 5
                                MoveCoor(ShipRoute(intRd).AxisX, _
                                    ShipRoute(intRd).AxisY, _
                                    ShipRoute(intRd).AxisH, _
                                    600)
                            End If
                            If InStr(.Unit, "Ships.") > 0 Then strUnit = Replace(.Unit, "Ships.", "ships.Ship$")
                            If InStr(.Unit, "ShipPack.") > 0 Then strUnit = Replace(.Unit, "ShipPack.", "ships.Ship$")
                            strOutput = "  " & .Ident & _
                                    " " & strUnit & _
                                    " " & Format(.Side, "0") & _
                                    " " & Format(dbX, "0.00") & _
                                    " " & Format(dbY, "0.00") & _
                                    " " & Format(intHead + 90, "0.0") & _
                                    " 0.0" & _
                                    " " & .ROF

                            ReDim Preserve Chief(Chief.Length)
                            Chief(Chief.Length - 1) = strOutput
                        End If
                    End If
                End If
            End If
        End With
    End Sub

    Public Sub PlaceTrain(ByRef intChief As Integer, _
                            ByRef ConvoyVeh(,) As String, _
                            ByRef MissSettings As Mission, _
                            ByRef Train() As Column, _
                            ByRef Station() As Location, _
                            ByRef Rail() As Waypoint, _
                            ByRef Chief() As String, _
                            ByRef ChiefMov() As String, _
                            ByRef ChiefRd() As String, _
                            ByRef RailWP() As String, _
                            ByRef INI_Settings As INI_Class)
        Dim intUnit As Integer
        Dim dbX As Double
        Dim dbY As Double
        Dim intHead As Integer
        Dim intRd As Integer
        Dim strOutput As String
        With Train(intChief)
            If .iFrom = .iTo Then 'Train at a named location
                If .ConType > 0 Then
                    If .Side = 1 Then
                        dbX = Station(.iFrom).AlliedX
                        dbY = Station(.iFrom).AlliedY
                        intHead = Station(.iFrom).AlliedH
                        MoveCoor(Station(.iFrom).AlliedX, _
                                    Station(.iFrom).AlliedY, _
                                    Station(.iFrom).AlliedH, _
                                    INI_Settings.sngStaticSep * (5 + .Size))
                    Else
                        dbX = Station(.iFrom).AxisX
                        dbY = Station(.iFrom).AxisY
                        intHead = Station(.iFrom).AxisH
                        MoveCoor(Station(.iFrom).AxisX, _
                                    Station(.iFrom).AxisY, _
                                    Station(.iFrom).AxisH, _
                                    INI_Settings.sngStaticSep * (5 + .Size))
                    End If
                    For intUnit = 1 To .Curr

                        strOutput = "  " & .Ident & Format(intUnit - 1, "0") & _
                                    " " & ConvoyVeh(intUnit, .ConType) & _
                                    " " & Format(.Side, "0") & _
                                    " " & Format(dbX, "########.00") & _
                                    " " & Format(dbY, "########.00") & _
                                    " " & Format(intHead + 90, "##0.0")
                        If InStr(strOutput, ".artillery") > 0 Then
                            strOutput = strOutput & _
                                    " " & Format(INI_Settings.sngDelay, "0.0") & _
                                    " " & Format(INI_Settings.sngRange, "0")
                        Else
                            strOutput = strOutput & " 0.0"
                        End If
                        MoveCoor(dbX, _
                                dbY, _
                                intHead, _
                                INI_Settings.sngStaticSep)

                        ReDim Preserve Chief(Chief.Length)
                        Chief(Chief.Length - 1) = strOutput
                    Next
                End If
            Else 'Train between locations

                For intRd = Rail.Length - 1 To 0 Step -1
                    If (Rail(intRd).iFrom = .iTo And _
                            Rail(intRd).iTo = .iFrom) Or _
                            (Rail(intRd).iFrom = .iFrom And _
                            Rail(intRd).iTo) = .iTo Then
                        If .Side = 1 Then
                            dbX = Rail(intRd).AlliedX
                            dbY = Rail(intRd).AlliedY
                            intHead = Rail(intRd).AlliedH
                        Else
                            dbX = Rail(intRd).AxisX
                            dbY = Rail(intRd).AxisY
                            intHead = Rail(intRd).AxisH
                        End If
                        Exit For
                    End If
                Next

                If intRd > 0 Then
                    If INI_Settings.iMovingDF > 0 Then
                        PlaceTrainMov(intChief, _
                                      intRd, _
                                      MissSettings, _
                                      Train, _
                                      Rail, _
                                      ChiefMov, _
                                      ChiefRd, _
                                      RailWP, _
                                      INI_Settings)
                    Else
                        If .ConType > 0 Then
                            If .Side = 1 Then
                                MoveCoor(Rail(intRd).AlliedX, _
                                    Rail(intRd).AlliedY, _
                                    Rail(intRd).AlliedH, _
                                    INI_Settings.sngStaticSep * (5 + .Size))
                            Else
                                MoveCoor(Rail(intRd).AxisX, _
                                    Rail(intRd).AxisY, _
                                    Rail(intRd).AxisH, _
                                    INI_Settings.sngStaticSep * (5 + .Size))
                            End If
                            For intUnit = 1 To .Curr

                                strOutput = "  " & .Ident & Format(intUnit - 1, "0") & _
                                            " " & ConvoyVeh(intUnit, .ConType) & _
                                            " " & Format(.Side, "0") & _
                                            " " & Format(dbX, "########.00") & _
                                            " " & Format(dbY, "########.00") & _
                                            " " & Format(intHead + 90, "##0.0")
                                If InStr(strOutput, ".artillery") > 0 Then
                                    strOutput = strOutput & _
                                        " " & Format(INI_Settings.sngDelay, "0.0") & _
                                        " " & Format(INI_Settings.sngRange, "0")
                                Else
                                    strOutput = strOutput & "0.0"
                                End If
                                MoveCoor(dbX, _
                                        dbY, _
                                        intHead, _
                                        INI_Settings.sngStaticSep)

                                ReDim Preserve Chief(Chief.Length)
                                Chief(Chief.Length - 1) = strOutput
                            Next
                        Else
                            'Nothing in here yet
                        End If
                    End If
                End If
            End If
        End With
    End Sub
    Public Sub PlaceCar(ByRef intChief As Integer, _
                        ByRef ConvoyInfo() As Convoy, _
                        ByRef MissSettings As Mission, _
                        ByRef Col() As Column, _
                        ByRef Locat() As Location, _
                        ByRef Road() As Waypoint, _
                        ByRef Chief() As String, _
                        ByRef ChiefMov() As String, _
                        ByRef ChiefRd() As String, _
                        ByRef RoadWp() As String, _
                        ByRef INI_Settings As INI_Class)
        Dim dbX As Double
        Dim dbY As Double
        Dim intHead As Integer
        Dim intRd As Integer
        Dim strOutput As String
        With Col(intChief)
            If .iFrom = .iTo Then 'Car at a named location
                If .Side = 1 Then
                    dbX = Locat(.iFrom).AlliedX
                    dbY = Locat(.iFrom).AlliedY
                    intHead = Locat(.iFrom).AlliedH
                Else
                    dbX = Locat(.iFrom).AxisX
                    dbY = Locat(.iFrom).AxisY
                    intHead = Locat(.iFrom).AxisH
                End If

                If .Side = 1 Then
                    MoveCoor(Locat(.iFrom).AlliedX, _
                                Locat(.iFrom).AlliedY, _
                                Locat(.iFrom).AlliedH, _
                                INI_Settings.sngStaticSep)
                Else
                    MoveCoor(Locat(.iFrom).AxisX, _
                                Locat(.iFrom).AxisY, _
                                Locat(.iFrom).AxisH, _
                                INI_Settings.sngStaticSep)
                End If

                strOutput = "  " & .Ident & _
                            " " & .Unit & _
                            " " & Format(.Side, "0") & _
                            " " & Format(dbX, "0.00") & _
                            " " & Format(dbY, "0.00") & _
                            " " & Format(intHead + 90, "0.0")
                If InStr(strOutput, ".artillery") > 0 Then
                    strOutput = strOutput & _
                                " " & Format(INI_Settings.sngDelay, "0.0") & _
                                " " & Format(INI_Settings.sngRange, "0")
                Else
                    strOutput = strOutput & " 0.0"
                End If

                ReDim Preserve Chief(Chief.Length)
                Chief(Chief.Length - 1) = strOutput


            Else 'Car between named locations
                For intRd = Road.Length - 1 To 1 Step -1
                    If (Road(intRd).iFrom = .iTo And _
                            Road(intRd).iTo = .iFrom) Or _
                            (Road(intRd).iFrom = .iFrom And _
                            Road(intRd).iTo = .iTo) Then
                        If .Side = 1 Then
                            dbX = Road(intRd).AlliedX
                            dbY = Road(intRd).AlliedY
                            intHead = Road(intRd).AlliedH
                        Else
                            dbX = Road(intRd).AxisX
                            dbY = Road(intRd).AxisY
                            intHead = Road(intRd).AxisH
                        End If
                        Exit For
                    End If
                Next
                If intRd > 0 Then
                    If (Locat(.iFrom).Moving) And _
                              (Road(intRd).iEnd - Road(intRd).Start > 2 * (INI_Settings.ColSpawn + 3)) And _
                              ((Road(intRd).iFrom = .iFrom And Road(intRd).AxisSP <= INI_Settings.ColSpawn) Or _
                              (Road(intRd).iTo = .iFrom And Road(intRd).AlliedSP < INI_Settings.ColSpawn)) Then
                        PlaceCarMoving(intChief, _
                                       intRd, _
                                       ConvoyInfo, _
                                       MissSettings, _
                                       Col, _
                                       Road, _
                                       ChiefMov, _
                                       ChiefRd, _
                                       RoadWp, _
                                        INI_Settings)
                    Else
                        If .Side = 1 Then
                            MoveCoor(Road(intRd).AlliedX, _
                                Road(intRd).AlliedY, _
                                Road(intRd).AlliedH, _
                                INI_Settings.sngStaticSep)
                        Else
                            MoveCoor(Road(intRd).AxisX, _
                                Road(intRd).AxisY, _
                                Road(intRd).AxisH, _
                                INI_Settings.sngStaticSep)
                        End If
                        strOutput = "  " & .Ident & _
                            " " & .Unit & _
                            " " & Format(.Side, "0") & _
                            " " & Format(dbX, "#######0.00") & _
                            " " & Format(dbY, "#######0.00") & _
                            " " & Format(intHead + 90, "##0.0")
                        If InStr(strOutput, ".artillery") > 0 Then
                            strOutput = strOutput & _
                                " " & Format(INI_Settings.sngDelay, "0.0") & _
                                " " & Format(INI_Settings.sngRange, "0")
                        Else
                            strOutput = strOutput & " 0.0"
                        End If

                        ReDim Preserve Chief(Chief.Length)
                        Chief(Chief.Length - 1) = strOutput
                    End If
                End If
            End If
        End With
    End Sub

    Public Sub PlaceTank(ByRef intChief As Integer, _
                            ByRef MissSettings As Mission, _
                            ByRef Col() As Column, _
                            ByRef Locat() As Location, _
                            ByRef Road() As Waypoint, _
                            ByRef Chief() As String, _
                            ByRef ChiefMov() As String, _
                            ByRef ChiefRd() As String, _
                            ByRef RoadWp() As String, _
                            ByRef INI_Settings As INI_Class, _
                            ByRef CamSettings As Campaign)
        Dim intUnit As Integer
        Dim dbX As Double
        Dim dbY As Double
        Dim intHead As Integer
        Dim strUnit As String
        Dim intRd As Integer
        Dim intDir As Integer
        Dim intStart As Integer
        Dim strOutput As String
        If Locat(Col(intChief).iTo).Side <> Col(intChief).Side Or _
                Locat(Col(intChief).iFrom).Side <> Col(intChief).Side Then
            PlaceTank_Engaged(intChief, _
                              MissSettings, _
                              Col, _
                              Locat, _
                              Road, _
                              Chief, _
                              ChiefMov, _
                              ChiefRd, _
                              RoadWp, _
                              INI_Settings, _
                              CamSettings)
            Exit Sub
        End If

        With Col(intChief)
            If .iFrom = .iTo Then 'Tanks at a named location
                If .Side = 1 Then
                    dbX = Locat(.iFrom).AlliedX
                    dbY = Locat(.iFrom).AlliedY
                    intHead = Locat(.iFrom).AlliedH
                    MoveCoor(Locat(.iFrom).AlliedX, _
                                Locat(.iFrom).AlliedY, _
                                Locat(.iFrom).AlliedH, _
                                INI_Settings.sngStaticSep * (1 + .Size))
                Else
                    dbX = Locat(.iFrom).AxisX
                    dbY = Locat(.iFrom).AxisY
                    intHead = Locat(.iFrom).AxisH
                    MoveCoor(Locat(.iFrom).AxisX, _
                                Locat(.iFrom).AxisY, _
                                Locat(.iFrom).AxisH, _
                                INI_Settings.sngStaticSep * (1 + .Size))
                End If


                intStart = InStr(.Unit, "-")
                intStart = intStart + 1
                strUnit = Trim(Mid(.Unit, intStart))
                If InStr(strUnit, "SU-") > 0 Then strUnit = Replace(strUnit, "SU-", "SU")
                strUnit = "vehicles.artillery.Artillery$" & strUnit
                intDir = Int(Rnd() * 2)
                If intDir = 0 Then intDir = -1
                For intUnit = 1 To .Size
                    MoveCoor(dbX, _
                            dbY, _
                            intHead, _
                            INI_Settings.sngStaticSep)
                    strOutput = "  " & .Ident & Format(intUnit - 1, "0") & _
                                " " & strUnit & _
                                " " & Format(.Side, "0") & _
                                " " & Format(dbX, "########.00") & _
                                " " & Format(dbY, "########.00") & _
                                " " & Format(intHead + 90, "##0.0")
                    If InStr(strOutput, ".artillery") > 0 Then
                        strOutput = strOutput & _
                                Format(INI_Settings.sngTankDly, " 0.0") & " " & _
                                Format(INI_Settings.sngTankRng, "0")
                    Else
                        strOutput = strOutput & " 0.0"
                    End If
                    If InStr(strOutput, ".artillery.Artillery") > 0 And InStr(.Unit, "Infantry.") < 1 Then
                        strOutput = Replace(strOutput, ".artillery.Artillery", ".stationary.Stationary")
                    End If

                    ReDim Preserve Chief(Chief.Length)
                    Chief(Chief.Length - 1) = strOutput
                Next
            Else
                For intRd = Road.Length - 1 To 1 Step -1
                    If (Road(intRd).iFrom = .iTo And _
                            Road(intRd).iTo = .iFrom) Or _
                            (Road(intRd).iFrom = .iFrom And _
                            Road(intRd).iTo = .iTo) Then
                        If .Side = 1 Then
                            dbX = Road(intRd).AlliedX
                            dbY = Road(intRd).AlliedY
                            intHead = Road(intRd).AlliedH
                        Else
                            dbX = Road(intRd).AxisX
                            dbY = Road(intRd).AxisY
                            intHead = Road(intRd).AxisH
                        End If
                        Exit For
                    End If
                Next
                If intRd > 1 Then
                    If (Locat(.iFrom).Moving) And _
                              (Road(intRd).iEnd - Road(intRd).Start > 2 * (INI_Settings.ColSpawn + 3)) And _
                              ((Road(intRd).iFrom = .iFrom And Road(intRd).AxisSP <= INI_Settings.ColSpawn) Or _
                              (Road(intRd).iTo = .iFrom And Road(intRd).AlliedSP < INI_Settings.ColSpawn)) Then
                        PlaceTankMoving(intChief, _
                                        intRd, _
                                        MissSettings, _
                                        Col, _
                                        Road, _
                                        ChiefMov, _
                                        ChiefRd, _
                                        RoadWp, _
                                        INI_Settings)
                    Else
                        If .Side = 1 Then
                            MoveCoor(Road(intRd).AlliedX, _
                                Road(intRd).AlliedY, _
                                Road(intRd).AlliedH, _
                                INI_Settings.sngStaticSep * (1 + .Size))
                        Else
                            MoveCoor(Road(intRd).AxisX, _
                                Road(intRd).AxisY, _
                                Road(intRd).AxisH, _
                                INI_Settings.sngStaticSep * (1 + .Size))
                        End If
                        intStart = InStr(.Unit, "-")
                        intStart = intStart + 1
                        strUnit = Trim(Mid(.Unit, intStart))
                        If InStr(strUnit, "SU-") > 0 Then strUnit = Replace(strUnit, "SU-", "SU")
                        strUnit = "vehicles.artillery.Artillery$" & strUnit
                        intDir = Int(Rnd() * 2)
                        If intDir = 0 Then intDir = -1
                        For intUnit = 1 To .Size
                            MoveCoor(dbX, _
                                dbY, _
                                intHead, _
                                INI_Settings.sngStaticSep)
                            strOutput = "  " & .Ident & Format(intUnit - 1, "0") & _
                                    " " & strUnit & _
                                    " " & Format(.Side, "0") & _
                                    " " & Format(dbX, "########.00") & _
                                    " " & Format(dbY, "########.00") & _
                                    " " & Format(intHead + 90, "##0.0")
                            If InStr(strOutput, ".artillery") > 0 Then
                                strOutput = strOutput & _
                                    Format(INI_Settings.sngTankDly, " 0.0") & " " & _
                                    Format(INI_Settings.sngTankRng, "0")
                            Else
                                strOutput = strOutput & " 0.0"
                            End If
                            If InStr(strOutput, ".artillery.Artillery") > 0 And InStr(.Unit, "Infantry.") < 1 Then
                                strOutput = Replace(strOutput, ".artillery.Artillery", ".stationary.Stationary")
                            End If

                            ReDim Preserve Chief(Chief.Length)
                            Chief(Chief.Length - 1) = strOutput
                        Next
                    End If
                End If
            End If
        End With
    End Sub
    Public Sub PlaceAC(ByRef bolerror As Boolean, _
                        ByRef strerror As String, _
                        ByRef BornPlace() As BornPlaceClass, _
                        ByRef ac_new() As AC_Type, _
                        ByRef Locat() As Location, _
                        ByRef Squad() As Squad_Type)
        Dim intFlight As Integer
        Dim dbDist As Double
        Dim dbShort As Double
        Dim intShort As Integer
        Dim intBorn As Integer
        If BornPlace.Length < 2 Then
            bolerror = True
            strerror = "No bornplace file found when generating mission"
            Exit Sub
        End If
        For intFlight = 1 To Squad.Length - 1
            With Squad(intFlight)
                If .iLoc > 0 Then

                    'Land or Seaplane Base
                    dbDist = Math.Sqrt(((Locat(.iLoc).X - BornPlace(1).X) ^ 2) + _
                        ((Locat(.iLoc).Y - BornPlace(1).Y) ^ 2))
                    dbShort = dbDist
                    intShort = 1
                    For intBorn = 1 To BornPlace.Length - 1
                        dbDist = Math.Sqrt(((Locat(.iLoc).X - BornPlace(intBorn).X) ^ 2) + _
                            ((Locat(.iLoc).Y - BornPlace(intBorn).Y) ^ 2))
                        If dbShort > dbDist Then
                            dbShort = dbDist
                            intShort = intBorn
                        End If
                    Next
                    For inttype = 1 To ac_new.Length - 1
                        If .Coop = ac_new(inttype).Coop Then
                            .DF = ac_new(inttype).DF
                        End If
                    Next
                    BornPlace(intShort).Active = True
                    If InStr(BornPlace(intShort).Aircraft, .DF & ";") < 1 Then
                        BornPlace(intShort).Aircraft = BornPlace(intShort).Aircraft & .DF & ";"
                    End If
                    BornPlace(intShort).Side = .Side
                    BornPlace(intShort).Loc = Locat(.iLoc).Loc
                    BornPlace(intShort).intLoc = .iLoc

                Else
                    'Aircraft Carrier
                    For intShort = BornPlace.Length - 1 To 1 Step -1
                        If .iLoc = BornPlace(intShort).intLoc Then Exit For
                    Next
                    If intShort > 0 Then
                        For inttype = 1 To ac_new.Length - 1
                            If .Coop = ac_new(inttype).Coop Then
                                .DF = ac_new(inttype).DF
                            End If
                        Next
                        If InStr(BornPlace(intShort).Aircraft, .DF & ";") < 1 Then
                            BornPlace(intShort).Aircraft = BornPlace(intShort).Aircraft & .DF & ";"
                        End If
                    End If
                End If
            End With
        Next
    End Sub
    Public Sub AdvanceDate(ByRef bolerror As Boolean, _
                        ByRef strerror As String, _
                        ByRef camsettings As Campaign)
        camsettings.dDate = DateAdd(DateInterval.Day, 1, camsettings.dDate)
    End Sub
    Public Sub GenProperties(ByRef bolerror As Boolean, _
                            ByRef strerror As String, _
                            ByRef strFolder As String, _
                            ByRef MisWeather As Integer, _
                            ByRef MisCloud As Integer, _
                            ByRef Transport() As Carry, _
                            ByRef Wind As Weather, _
                            ByRef BornPlace() As BornPlaceClass, _
                            ByRef camsettings As Campaign, _
                            ByRef MissSettings As Mission, _
                            ByRef Infantry() As Column, _
                            ByRef Locat() As Location, _
                            ByRef strFrontLine() As String, _
                            ByRef strACMove() As String, _
                            ByRef strBdgDown() As String, _
                            ByRef Squad() As Squad_Type, _
                            ByRef UseSquad As Integer, _
                            ByRef Weapon() As Weap, _
                            ByRef SupplyAC() As AC_Supply, _
                            ByRef INI_Settings As INI_Class, _
                            ByRef MisTime As Single)

        Dim intCount As Integer
        Dim i As Integer
        Dim iACSquad As Integer
        Dim ACSquad() As Squad_Type
        Dim totACSquad As Integer
        Dim iAC As Integer
        Dim sb As New StringBuilder

        'Mission Name
        sb.AppendLine("Name Forgotten Skies " & _
                camsettings.Battle & " " & _
                Format(camsettings.dDate, "mmm d, yyyy"))
        'Short name
        sb.AppendLine("Short Forgotten Skies Dogfight Mission ")
        'Description
        sb.Append("Description ")
        sb.Append("<ARMY NONE>\n\nType: " & _
                camsettings.Battle & "\n\n" & _
                "n\nOrders: \n\nSelect your Squad and aircraft before proceeding.\n" & _
                "Type: " & camsettings.Battle & " \n\n" & _
                "Date: " & Format(camsettings.dDate, "dd/mm/yy") & " \n" & _
                "Time: " & Format(MisTime, "00") & ":00" & " \n" & _
                "Weather: " & Format(MisWeather, "0") & " \n" & _
                "Cloud Height: " & Format(MisCloud, "0") & " meters \n" & _
                "Wind Direction: " & Format(Wind.Direction, "0") & " deg \n" & _
                "Wind Speed: " & Format(Wind.Velocity * 3.6, "0") & " km/h \n\n" & _
                "</ARMY>\n")

        'Red Briefing
        sb.Append("<ARMY RED>")
        sb.Append("Type: " & camsettings.Battle & " \n\n" & _
                "Date: " & Format(camsettings.dDate, "dd/mm/yy") & " \n" & _
                "Time: " & Format(MisTime, "00") & ":00" & " \n" & _
                "Weather: " & Format(MisWeather, "0") & " \n" & _
                "Cloud Height: " & Format(MisCloud, "0") & " meters \n" & _
                "Wind Direction: " & Format(Wind.Direction, "0") & " deg \n" & _
                "Wind Speed: " & Format(Wind.Velocity * 3.6, "0") & " km/h \n\n" & _
                "Active Airfields: \n\n")
        For intCount = 1 To BornPlace.Length - 1
            With BornPlace(intCount)
                totACSquad = 0
                ReDim ACSquad(totACSquad)
                For iAC = 1 To Squad.Length - 1
                    If .Loc = Squad(iAC).Loc And Squad(iAC).Side = 1 And Squad(iAC).Number > 0 Then
                        If totACSquad < 1 Then
                            totACSquad = totACSquad + 1
                            ReDim Preserve ACSquad(totACSquad)
                            ACSquad(totACSquad).Coop = Squad(iAC).Coop
                            ACSquad(totACSquad).Number = Squad(iAC).Number
                        Else
                            For iACSquad = totACSquad To 1 Step -1
                                If ACSquad(iACSquad).Coop = Squad(iAC).Coop Then
                                    ACSquad(iACSquad).Number = ACSquad(iACSquad).Number + Squad(iAC).Number
                                    Exit For
                                End If
                            Next
                            If iACSquad < 1 Then
                                totACSquad = totACSquad + 1
                                ReDim Preserve ACSquad(totACSquad)
                                ACSquad(totACSquad).Coop = Squad(iAC).Coop
                                ACSquad(totACSquad).Number = Squad(iAC).Number
                            End If
                        End If
                    End If
                Next
                If totACSquad > 0 Then
                    sb.Append(.Loc & "\n")
                    If .intLoc > 0 Then
                        If Locat(.intLoc).Loc = camsettings.RuHome Then
                            sb.Append("Red Supply Base\n")
                        End If
                        If Locat(.intLoc).Suppressed > 0 Then
                            sb.Append("Suppressed\n")
                        Else
                            sb.Append("Not Suppressed\n")
                        End If
                        If Locat(.intLoc).Infantry > 0 Then
                            sb.Append("Infantry Available\n")
                        End If
                        sb.Append("Fuel Limit: " & Format(Locat(.intLoc).FuelLimit, "0") & "\n")
                    End If

                    For iACSquad = 1 To totACSquad
                        sb.Append("     " & ACSquad(iACSquad).Coop & ":" & ACSquad(iACSquad).Number & "\n")
                    Next
                End If
            End With
        Next
        If strACMove.Length > 1 Then
            sb.Append("\n\n" & "Squadrons Moved by Mission Generator:")
            For intCount = 1 To strACMove.Length - 1
                sb.Append("\n" & strACMove(intCount))
            Next
        End If
        If strFrontLine.Length > 1 Then
            sb.Append("\n\n" & "Locations Being Contested:")
            For intCount = 1 To strFrontLine.Length - 1
                sb.Append("\n" & strFrontLine(intCount))
            Next
        End If
        If strBdgDown.Length > 1 Then
            sb.Append("\n\n" & "Bridges Destroyed in the Last Mission:")
            For intCount = 1 To strBdgDown.Length - 1
                sb.Append("\n" & strBdgDown(intCount))
            Next
        End If
        sb.Append("\n\nObjective: Determined by players.\n")
        sb.Append("</ARMY>\n")
        'Blue Briefing
        sb.Append("<ARMY BLUE>")
        sb.Append("Type: " & camsettings.Battle & " \n\n" & _
                "Date: " & Format(camsettings.dDate, "dd/mm/yy") & " \n" & _
                "Time: " & Format(MisTime, "00") & ":00" & " \n" & _
                "Weather: " & Format(MisWeather, "0") & " \n" & _
                "Cloud Height: " & Format(MisCloud, "0") & " meters \n" & _
                "Wind Direction: " & Format(Wind.Direction, "0") & " deg \n" & _
                "Wind Speed: " & Format(Wind.Velocity * 3.6, "0") & " km/h \n\n" & _
                "Active Airfields: \n\n")
        For intCount = 1 To BornPlace.Length - 1
            With BornPlace(intCount)
                totACSquad = 0
                ReDim ACSquad(totACSquad)
                For iAC = 1 To Squad.Length - 1
                    If .Loc = Squad(iAC).Loc And Squad(iAC).Side = 2 And Squad(iAC).Number > 0 Then
                        If totACSquad < 1 Then
                            totACSquad = totACSquad + 1
                            ReDim Preserve ACSquad(totACSquad)
                            ACSquad(totACSquad).Coop = Squad(iAC).Coop
                            ACSquad(totACSquad).Number = Squad(iAC).Number
                        Else
                            For iACSquad = totACSquad To 1 Step -1
                                If ACSquad(iACSquad).Coop = Squad(iAC).Coop Then
                                    ACSquad(iACSquad).Number = ACSquad(iACSquad).Number + Squad(iAC).Number
                                    Exit For
                                End If
                            Next
                            If iACSquad < 1 Then
                                totACSquad = totACSquad + 1
                                ReDim Preserve ACSquad(totACSquad)
                                ACSquad(totACSquad).Coop = Squad(iAC).Coop
                                ACSquad(totACSquad).Number = Squad(iAC).Number
                            End If
                        End If
                    End If
                Next
                If totACSquad > 0 Then
                    sb.Append(.Loc & "\n")
                    If .intLoc > 0 Then
                        If Locat(.intLoc).Loc = camsettings.DeHome Then
                            sb.Append("Blue Supply Base\n")
                        End If
                        If Locat(.intLoc).Suppressed > 0 Then
                            sb.Append("Suppressed\n")
                        Else
                            sb.Append("Not Suppressed\n")
                        End If
                        If Locat(.intLoc).Infantry > 0 Then
                            sb.Append("Infantry Available\n")
                        End If
                        sb.Append("Fuel Limit: " & Format(Locat(.intLoc).FuelLimit, "0") & "\n")
                    End If

                    For iACSquad = 1 To totACSquad
                        sb.Append("     " & ACSquad(iACSquad).Coop & ":" & ACSquad(iACSquad).Number & "\n")
                    Next
                End If
            End With
        Next
        If strACMove.Length > 1 Then
            sb.Append("\n\n" & "Squadrons Moved by Mission Generator:")
            For intCount = 1 To strACMove.Length - 1
                sb.Append("\n" & strACMove(intCount))
            Next
        End If
        If strFrontLine.Length > 1 Then
            sb.Append("\n\n" & "Locations Being Contested:")
            For intCount = 1 To strFrontLine.Length - 1
                sb.Append("\n" & strFrontLine(intCount))
            Next
        End If
        If strBdgDown.Length > 1 Then
            sb.Append("\n\n" & "Bridges Destroyed in the Last Mission:")
            For intCount = 1 To strBdgDown.Length - 1
                sb.Append("\n" & strBdgDown(intCount))
            Next
        End If
        sb.Append("\n\nObjective: Determined by players.\n")
        sb.AppendLine("</ARMY>\n")

        'Home Base Information
        

        For intCount = 1 To BornPlace.Length - 1

            If BornPlace(intCount).intLoc <> 0 And _
                    BornPlace(intCount).Active And _
                    BornPlace(intCount).Side > 0 Then
                sb.Append("<ARMY BASES>")
                sb.Append(BornPlace(intCount).Loc & ":")
                If BornPlace(intCount).intLoc < 0 Then
                    sb.Append(Format(BornPlace(intCount).Side, "0") & ":" & _
                        Format(BornPlace(intCount).X, "0") & ":" & _
                        Format(BornPlace(intCount).Y, "0") & ":" & _
                        Format(INI_Settings.BornPlaceRadius * 3, "0") & ":0:0:0:100:")
                Else
                    sb.Append(Format(BornPlace(intCount).Side, "0") & ":" & _
                        Format(BornPlace(intCount).X, "0") & ":" & _
                        Format(BornPlace(intCount).Y, "0") & ":" & _
                        Format(INI_Settings.BornPlaceRadius, "0") & ":" & _
                        Format(Locat(BornPlace(intCount).intLoc).Supply, "0") & ":" & _
                        Format(Locat(BornPlace(intCount).intLoc).Fuel, "0") & ":" & _
                        Format(Locat(BornPlace(intCount).intLoc).Suppressed, "0") & ":" & _
                        Format(Locat(BornPlace(intCount).intLoc).FuelLimit, "0"))
                End If


                'Use the Aircraft File

                For i = 1 To Squad.Length - 1
                    If Squad(i).iLoc = BornPlace(intCount).intLoc Then
                        sb.Append(":" & Squad(i).Coop & "=" & _
                            Squad(i).DF & "=" & _
                            Squad(i).Number)
                    End If
                Next
                sb.AppendLine("</ARMY BASES>\n")
            End If
        Next


        'Infantry Information


        For intCount = 1 To BornPlace.Length - 1

            If BornPlace(intCount).intLoc > 0 And _
                    BornPlace(intCount).Active And _
                    BornPlace(intCount).Side > 0 Then

                For i = 1 To Infantry.Length - 1
                    With Infantry(i)
                        If .iFrom = BornPlace(intCount).intLoc Then
                            sb.Append("<INFANTRY>")
                            sb.Append(BornPlace(intCount).Loc & ":" & _
                                .Ident)
                            sb.AppendLine("</INFANTRY>\n")
                        End If
                    End With
                Next
            End If
        Next


        'Weapons Information
        Select Case INI_Settings.Daemon
            Case 0

                For intCount = 1 To Weapon.Length - 1
                    sb.Append("<ARMY WEAPONS>")
                    sb.Append(Weapon(intCount).AC & ":" & _
                        Weapon(intCount).Weapon)
                    sb.AppendLine("</ARMY WEAPONS>\n")
                Next

        End Select
        'Supply AC Information
        If SupplyAC.Length < 2 Then
            ReDim Preserve SupplyAC(SupplyAC.Length)
            SupplyAC(SupplyAC.Length - 1).Coop = "redac"
            SupplyAC(SupplyAC.Length - 1).DF = "redac"
            SupplyAC(SupplyAC.Length - 1).Coop = 5

        End If

        sb.Append("<ARMY SUPPLY>")
        sb.Append(camsettings.RuHome & ":" & _
                        camsettings.DeHome & ":" & _
                        MissSettings.SupplyLoad)
        For iAC = 1 To SupplyAC.Length - 1
            sb.Append(":" & SupplyAC(iAC).DF)

        Next
        sb.AppendLine("</ARMY SUPPLY>\n")

        'Transport Information
        

        If Transport.Length > 1 Then
            For intCount = 1 To Transport.Length - 1
                sb.Append("<ARMY TRANSPORT>")
                sb.Append(Transport(intCount).Main & ":" & _
                            Transport(intCount).Secondary)
                sb.AppendLine("</ARMY TRANSPORT>\n")
            Next
        Else
            sb.Append("<ARMY TRANSPORT>")
            sb.Append("1000_Chief:2000_Chief")
            sb.AppendLine("</ARMY TRANSPORT>\n")
        End If


        'Save the properties file

        'Using outfile As New StreamWriter(strFolder & "\dcgmission.properties")
        'outfile.Write(sb.ToString())
        'outfile.Close()
        'End Using
        FileOpen(1, strFolder & "\dcgmission.properties", OpenMode.Output, OpenAccess.Write, OpenShare.Shared)
        Print(1, sb.ToString)
        FileClose(1)
    End Sub
    Public Sub GenColumnFile(ByRef bolerror As Boolean, _
                            ByRef strerror As String, _
                            ByRef Col() As Column, _
                            ByRef Ship() As Column, _
                            ByRef Train() As Column, _
                            ByRef Infantry() As Column, _
                            ByRef INI_Settings As INI_Class)
        Dim intLine As Integer
        Dim strOutput As String
        Dim sb As New StringBuilder
        If Col.Length > 1 Then
            For intLine = 1 To Col.Length - 1
                strOutput = Col(intLine).Ident & " " & _
                        Col(intLine).Unit & " " & _
                        Format(Col(intLine).Side, "0") & " " & _
                        "@" & Col(intLine).sFrom & " " & _
                        "@" & Col(intLine).sTo & " " & _
                        "$" & Col(intLine).Orig & " " & _
                        "D=" & Format(Col(intLine).Direction, "0") & " " & _
                        "S=" & Format(Col(intLine).Curr, "0") & " " & _
                        "LOAD=" & Format(Col(intLine).AllowLoad, "0")
                sb.AppendLine(Trim(strOutput))
            Next
        End If
        If Infantry.Length > 1 Then
            For intLine = 1 To Infantry.Length - 1
                strOutput = Infantry(intLine).Ident & " " & _
                        Infantry(intLine).Unit & " " & _
                        Format(Infantry(intLine).Side, "0") & " " & _
                        "@" & Infantry(intLine).sFrom & " " & _
                        "@" & Infantry(intLine).sTo & " " & _
                        "$" & Infantry(intLine).Orig & " " & _
                        "D=" & Format(Infantry(intLine).Direction, "0") & " " & _
                        "S=" & Format(Infantry(intLine).Curr, "0") & " " & _
                        "LOAD=" & Format(Col(intLine).AllowLoad, "0")
                sb.AppendLine(Trim(strOutput))
            Next
        End If
        If Ship.Length > 1 Then
            For intLine = 1 To Ship.Length - 1
                strOutput = Ship(intLine).Ident & " " & _
                    Ship(intLine).Unit & " " & _
                    Format(Ship(intLine).Side, "0") & " " & _
                    Ship(intLine).ROF & " " & _
                    "@" & Ship(intLine).sFrom & " " & _
                    "@" & Ship(intLine).sTo & " " & _
                    "$" & Ship(intLine).Orig & " " & _
                    "D=" & Format(Ship(intLine).Direction, "0") & " " & _
                    "S=" & Format(Ship(intLine).Curr, "0") '& " " & _
                '"LOAD=" & Format(Col(intLine).AllowLoad, "0")
                sb.AppendLine(Trim(strOutput))
            Next
        End If
        If Train.Length > 1 Then
            For intLine = 1 To Train.Length - 1
                strOutput = Train(intLine).Ident & " " & _
                        Train(intLine).Unit & " " & _
                        Format(Train(intLine).Side, "0") & " " & _
                        "@" & Train(intLine).sFrom & " " & _
                        "@" & Train(intLine).sTo & " " & _
                        "$" & Train(intLine).Orig & " " & _
                        "D=" & Format(Train(intLine).Direction, "0") & " " & _
                        "S=" & Format(Train(intLine).Curr, "0") '& " " & _
                '"LOAD=" & Format(Col(intLine).AllowLoad, "0")
                sb.AppendLine(Trim(strOutput))
            Next
        End If

        Using outfile As New StreamWriter(INI_Settings.sCampaign & "\columns.dcg")
            outfile.Write(sb.ToString())
            outfile.Close()
        End Using
    End Sub

    Public Sub RestoreOrigCol(ByRef strUnit As String, _
                        ByRef strOriginal As String)
        Dim intStart As Integer
        intStart = InStr(strUnit, ".")
        If intStart > 0 Then
            strUnit = Left(strUnit, intStart)
            strUnit = Trim(strUnit & strOriginal)
        End If
    End Sub
    Public Sub GenStatFile(ByRef bolerror As Boolean, _
                            ByRef strerror As String, _
                            ByRef Stat() As Stationary, _
                            ByRef INI_Settings As INI_Class)
        Dim intLine As Integer
        Dim strOutput As String
        Dim sb As New StringBuilder
        strOutput = "[NStationary]"
        sb.AppendLine(strOutput)
        For intLine = 1 To Stat.Length - 1
            With Stat(intLine)
                If .Active Then
                    strOutput = "  "
                Else
                    strOutput = "X "
                End If
                strOutput = strOutput & .Ident & " " & _
                        .Unit & " " & _
                        Format(.Side, "0") & " " & _
                        Format(.X, "0.00") & " " & _
                        Format(.Y, "0.00") & " " & _
                        Format(.Head, "0.00") & " " & _
                        .Other
            End With
            sb.AppendLine(strOutput)
        Next
        'Using outfile As New StreamWriter(INI_Settings.sCampaign & "\stationary.dcg")
        'outfile.Write(sb.ToString())
        'outfile.Close()
        'End Using
        FileOpen(1, INI_Settings.sCampaign & "\stationary.dcg", OpenMode.Output, OpenAccess.Write, OpenShare.Shared)
        Print(1, sb.ToString)
        FileClose(1)
    End Sub

    Public Sub GenTerrFile(ByRef bolerror As Boolean, _
                            ByRef strerror As String, _
                            ByRef Locat() As Location, _
                            ByRef Station() As Location, _
                            ByRef Harbor() As Location, _
                            ByRef ini_settings As INI_Class)
        Dim intLine As Integer
        Dim strOutput As String
        Dim sb As New StringBuilder
        For intLine = 1 To Locat.Length - 1
            With Locat(intLine)
                strOutput = .Loc & " " & _
                        Format(.Side, "0") & " " & _
                        Format(.X, "0.00") & " " & _
                        Format(.Y, "0.00") & " " & _
                        "allied=" & Format(.Allied, "0") & " " & _
                        "axis=" & Format(.Axis, "0") & " " & _
                        "supply=" & Format(.Supply, "0") & " " & _
                        "fuel=" & Format(.Fuel, "0") & " " & _
                        "points=" & Format(.Points, "0") & " " & _
                        "suppressed=" & Format(.Suppressed, "0") & " " & _
                        "fuellimit=" & Format(.FuelLimit, "0") & " " & _
                        "infantry=" & Format(.Infantry, "0") & " " & _
                        "manufacture=" & Format(.Manufacture, "0.00")

            End With
            sb.AppendLine(strOutput)
        Next
        For intLine = 1 To Station.Length - 1
            With Station(intLine)
                strOutput = .Loc & " " & _
                        Format(.Side, "0") & " " & _
                        Format(.X, "0.00") & " " & _
                        Format(.Y, "0.00") & " " & _
                        "allied=" & Format(.Allied, "0") & " " & _
                        "axis=" & Format(.Axis, "0") & " " & _
                        "points=" & Format(.Points, "0")
            End With
            sb.AppendLine(strOutput)
        Next
        For intLine = 1 To Harbor.Length - 1
            With Harbor(intLine)
                strOutput = .Loc & " " & _
                        Format(.Side, "0") & " " & _
                        Format(.X, "0.00") & " " & _
                        Format(.Y, "0.00") & " " & _
                        "allied=" & Format(.Allied, "0") & " " & _
                        "axis=" & Format(.Axis, "0") & " " & _
                        "points=" & Format(.Points, "0")
            End With
            sb.AppendLine(strOutput)
        Next
        'Using outfile As New StreamWriter(ini_settings.sCampaign & "\territory.dcg")
        'outfile.Write(sb.ToString())
        'outfile.Close()
        'End Using
        FileOpen(1, ini_settings.sCampaign & "\territory.dcg", OpenMode.Output, OpenAccess.Write, OpenShare.Shared)
        Print(1, sb.ToString)
        FileClose(1)
    End Sub

    Public Sub GenLocFile(ByRef bolerror As Boolean, _
                            ByRef strerror As String, _
                            ByRef Locat() As Location, _
                            ByRef Station() As Location, _
                            ByRef Harbor() As Location, _
                            ByRef INI_Settings As INI_Class)
        Dim intLine As Integer
        Dim strOutput As String
        Dim sb As New StringBuilder
        For intLine = 1 To Locat.Length - 1
            With Locat(intLine)
                strOutput = .Loc & " " & _
                        Format(.Side, "0") & " " & _
                        Format(.X, "0.00") & " " & _
                        Format(.Y, "0.00")
            End With
            sb.AppendLine(strOutput)
        Next
        For intLine = 1 To Station.Length - 1
            With Station(intLine)
                strOutput = .Loc & " " & _
                        Format(.Side, "0") & " " & _
                        Format(.X, "0.00") & " " & _
                        Format(.Y, "0.00")
            End With
            sb.AppendLine(strOutput)
        Next
        For intLine = 1 To Harbor.Length - 1
            With Harbor(intLine)
                strOutput = .Loc & " " & _
                        Format(.Side, "0") & " " & _
                        Format(.X, "0.00") & " " & _
                        Format(.Y, "0.00")
            End With
            sb.AppendLine(strOutput)
        Next
        'Using outfile As New StreamWriter(INI_Settings.sCampaign & "\locations.dcg")
        'outfile.Write(sb.ToString())
        'outfile.Close()
        'End Using
        FileOpen(1, INI_Settings.sCampaign & "\locations.dcg", OpenMode.Output, OpenAccess.Write, OpenShare.Shared)
        Print(1, sb.ToString)
        FileClose(1)
    End Sub

    

    Public Sub GenCampFile(ByRef bolerror As Boolean, _
                            ByRef strerror As String, _
                            ByRef camsettings As Campaign, _
                            ByRef MissSettings As Mission, _
                            ByRef SupplyAC() As AC_Supply, _
                            ByRef RedCountry() As String, _
                            ByRef BlueCountry() As String, _
                            ByRef INI_Settings As INI_Class)
        Dim i As Integer
        Dim sb As New StringBuilder
        'This sub saves the campaign file information back into the campaign folder
        With camsettings
            sb.AppendLine("[CAMPAIGN]")
            sb.AppendLine("  Campaign=" & .Camp)
            sb.AppendLine("  Battle=" & .Battle)
            sb.AppendLine("  Map=" & .Map)
            sb.AppendLine("  Route=" & .RouteName)
            sb.AppendLine("  BlueSpawn=" & .DeZone)
            sb.AppendLine("  RedSpawn=" & .RuZone)
            sb.AppendLine("  RedNavalStop=" & .RuNavalStop)
            sb.AppendLine("  BlueNavalStop=" & .DeNavalStop)
            sb.AppendLine("  RedHomeBase=" & .RuHome)
            sb.AppendLine("  BlueHomeBase=" & .DeHome)
            sb.AppendLine("  RedSeaHomeBase=" & .RuSeaHome)
            sb.AppendLine("  BlueSeaHomeBase=" & .DeSeaHome)
            sb.AppendLine("  Date=" & Format(.dDate, "MMM d, yyyy"))
            sb.AppendLine("  End=" & Format(.EndDate, "MMM d, yyyy"))
            sb.AppendLine()
        End With
        With MissSettings
            sb.AppendLine("[Mission]")
            sb.AppendLine("  StartTime=" & Format(.StartTime, "0.0"))
            sb.AppendLine("  EndTime=" & Format(.EndTime, "0.0"))
            sb.AppendLine("  BCloudType=" & Format(.BCloudType, "0"))
            sb.AppendLine("  WCloudType=" & Format(.WCloudType, "0"))
            sb.AppendLine("  LCloudAlt=" & Format(.LCloud, "0"))
            sb.AppendLine("  HCloudAlt=" & Format(.HCloud, "0"))
            sb.AppendLine("  LWindVelocity=" & Format(.LWindVelocity, "0"))
            sb.AppendLine("  HWindVelocity=" & Format(.HWindVelocity, "0"))
            sb.AppendLine("  LWindDirection=" & Format(.LWindDirection, "0"))
            sb.AppendLine("  HWindDirection=" & Format(.HWindDirection, "0"))
            sb.AppendLine("  LWindTop=" & Format(.LWindTop, "0"))
            sb.AppendLine("  HWindTop=" & Format(.HWindtop, "0"))
            sb.AppendLine("  BWindTurbulence=" & Format(.BWindTurbulence, "0"))
            sb.AppendLine("  WWindTurbulence=" & Format(.WWindTurbulence, "0"))
            sb.AppendLine("  BWindGust=" & Format(.BWindGust, "0"))
            sb.AppendLine("  WWindGust=" & Format(.WWindGust, "0"))
            sb.AppendLine("[SUPPRESSION]")
            sb.AppendLine("  BaseSuppression=" & Format(.BaseSupp, "0"))
            sb.AppendLine("  BaseSupply=" & Format(.BaseSupply, "0"))
            sb.AppendLine("  BaseDistance=" & Format(.BaseDist, "0"))
            sb.AppendLine("  BaseFuel=" & Format(.BaseFuel, "0"))
            sb.AppendLine("  FuelLimit=" & Format(.FuelLimit, "0"))
            sb.AppendLine("  MaxFuel=" & Format(.MaxFuel, "0"))
            sb.AppendLine("[BRIDGES]")
            sb.AppendLine("  Bridge=" & Format(.Bridge, "0"))
            sb.AppendLine("  Convoy=" & Format(.Convoy, "0.00"))
            sb.AppendLine("[SUPPY_AIRCRAFT]")
            If SupplyAC.Length > 1 Then
                For i = 1 To SupplyAC.Length - 1
                    sb.AppendLine("  SupplyAC=" & SupplyAC(i).Coop & "," & _
                                                Format(SupplyAC(i).Supply, "0"))
                Next
            End If
            sb.AppendLine("  SupplyLoad=" & .SupplyLoad)
            sb.AppendLine("  AirDropRange=" & Format(.AirDropRange, "0"))
            sb.AppendLine("[PARA_DROP]")
            sb.AppendLine("  ParaDrop=" & Format(.ParaDrop, "0"))
            sb.AppendLine("  ParaRange=" & Format(.ParaRange, "0"))
            sb.AppendLine("[FACTORY]")
            sb.AppendLine("  FactRepair=" & Format(.FactRepair, "0.00"))
            sb.AppendLine("[BASES]")
            sb.AppendLine("  RedRadar=" & .RedRadar)
            sb.AppendLine("  BlueRadar=" & .BlueRadar)
            sb.AppendLine("  Contested=" & Format(.Contested, "0.00"))
            If RedCountry.Length > 1 Then
                For i = 1 To RedCountry.Length - 1
                    sb.AppendLine("  RedCountry=" & RedCountry(i))
                Next
            End If
            If BlueCountry.Length > 0 Then
                For i = 1 To BlueCountry.Length - 1
                    sb.AppendLine("  BlueCountry=" & BlueCountry(i))
                Next
            End If
        End With
        With INI_Settings
            sb.AppendLine("[MOVING_DF]")
            sb.AppendLine("  MovingDF=" & Format(.iMovingDF, "0"))
            sb.AppendLine("  MovingDist=" & Format(.iMovingDist, "0"))
            sb.AppendLine("  ColDelay=" & Format(.ColDelay, "0"))
            sb.AppendLine("  TrainDelay=" & Format(.TrainDelay, "0"))
            sb.AppendLine("  ShipSpeed=" & Format(.ShipSpeed, "0.00"))
            sb.AppendLine("  ShipSep=" & Format(.ShipSep, "0"))
            sb.AppendLine("  ColSpawn=" & Format(.ColSpawn, "0"))
            sb.AppendLine("[SPAWN_RATES]")
            sb.AppendLine("  AircraftSupply=" & Format(.ACSupply, "0"))
            sb.AppendLine("  FactorySpawn=" & Format(.FactorySpawn, "0.00"))
            sb.AppendLine("  ShipSpawn=" & Format(.ShipSpawn, "0.00"))
            sb.AppendLine("  TrainSpawn=" & Format(.TrainSpawn, "0.00"))
            sb.AppendLine("  ColumnSpawn=" & Format(.ColumnSpawn, "0.00"))
            sb.AppendLine("[AIRBASES]")
            sb.AppendLine("  BornPlaceRadius=" & Format(.BornPlaceRadius, "0"))
            sb.AppendLine("[ARTILLERY_TANKS]")
            sb.AppendLine("  Range=" & Format(.sngRange, "0"))
            sb.AppendLine("  Delay=" & Format(.sngDelay, "0.0"))
            sb.AppendLine("  TankRng=" & Format(.sngTankRng, "0"))
            sb.AppendLine(" TankDly=" & Format(.sngTankDly, "0.0"))
            sb.AppendLine(" StaticSep=" & Format(.sngStaticSep, "0.0"))
            sb.AppendLine("[SUPPLY_FUEL]")
            sb.AppendLine("  MinFuel=" & Format(.intMinFuel, "0"))
            sb.AppendLine("  MinSupply=" & Format(.intMinSup, "0"))
            sb.AppendLine("[Factory_Plate]")
            sb.AppendLine("  Explosion=" & Format(.sExplosion, "0.000"))
            sb.AppendLine("[OTHER]")
            sb.AppendLine("  ShowDestFact=" & Format(.intShowDestFact, "0"))
            sb.AppendLine("  RebuildColumn=" & Format(.intRebuildCol, "0"))
            sb.AppendLine("  MissionLength=" & Format(.MisLength, "0"))
        End With
        'Using outfile As New StreamWriter(INI_Settings.sCampaign & "\campaign.dcg")
        'outfile.Write(sb.ToString())
        'outfile.Close()
        'End Using
        FileOpen(1, INI_Settings.sCampaign & "\campaign.dcg", OpenMode.Output, OpenAccess.Write, OpenShare.Shared)
        Print(1, sb.ToString)
        FileClose(1)
    End Sub

    Public Sub GenINIFile(ByRef bolerror As Boolean, _
                            ByRef strerror As String, _
                            ByRef INI_Settings As INI_Class)
        Dim sb As New StringBuilder

        With INI_Settings
            If Right(.sCampaign, 1) <> "\" Then .sCampaign = .sCampaign & "\"
            If Right(.sServer, 1) <> "\" Then .sCampaign = .sServer & "\"
            If Right(.sData, 1) <> "\" Then .sCampaign = .sData & "\"
            sb.AppendLine("Campaign=" & .sCampaign)
            sb.AppendLine("IL2Path=" & .sServer)
            sb.AppendLine("LogFileDate=" & .sINIDate)
            sb.AppendLine("DataFiles=" & .sData)

        End With
        'Using outfile As New StreamWriter(INI_File)
        'outfile.Write(sb.ToString())
        'outfile.Close()
        'End Using
        FileOpen(1, INI_File, OpenMode.Output, OpenAccess.Write, OpenShare.Shared)
        Print(1, sb.ToString)
        FileClose(1)
    End Sub
    Public Sub GenCFGFile(ByRef bolerror As Boolean, _
                            ByRef strerror As String)
        
        'Using outfile As New StreamWriter(INI_File)
        'outfile.Write(sb.ToString())
        'outfile.Close()
        'End Using

        'TODO: WRITE Ini Location to App.Config


        'REMOVED In favor of app.config
        'FileOpen(1, CFG_File, OpenMode.Output, OpenAccess.Write, OpenShare.Shared)
        'Print(1, "INI_FILE=" & INI_File)
        'FileClose(1)
    End Sub

    Public Sub CleanUpStat(ByRef bolerror As Boolean, _
                            ByRef strerror As String, _
                            ByRef Stat() As Stationary, _
                        ByRef Locat() As Location)
        'This sub does a final check on static objects and removes any at an enemy location
        Dim intStatCnt As Integer
        If Stat.Length < 2 Then
            bolerror = True
            strerror = "Could not find statics in -CleanUpStat-"
            Exit Sub
        End If
        For intStatCnt = 1 To Stat.Length - 1
            With Stat(intStatCnt)
                Select Case .Side
                    Case Is = 0
                        .Active = True
                    Case Is = 1
                        If Locat(.intLoc).Side = 2 Then .Active = False
                    Case Is = 2
                        If Locat(.intLoc).Side = 1 Then .Active = False
                End Select
            End With
        Next
    End Sub

    Public Sub BackupCampaign(ByRef bolerror As Boolean, _
                        ByRef strerror As String, _
                        ByRef camsettings As Campaign, _
                        ByRef INI_Settings As INI_Class)
        'This sub backs up the campaign as eventlog to a backup folder
        Dim strBackUp As String = ""
        Dim strCount As String = ""
        Dim intCount As Integer
        strBackUp = INI_Settings.sMainFolder & "\backup\"
        If Not My.Computer.FileSystem.DirectoryExists(strBackUp) Then
            MkDir(strBackUp)
        End If
        For intCount = 0 To 99
            strCount = strBackUp & camsettings.Battle & "_" & _
                    Format(Date.Today, "MMM_dd") & "_" & _
                    Format(intCount, "00") & "\"
            If Dir(strCount, vbDirectory) = "" Then
                Exit For
            End If
        Next
        strBackUp = strCount
        If Not My.Computer.FileSystem.DirectoryExists(strBackUp) Then
            MkDir(strCount)
        End If
        strCount = INI_Settings.sServer & "\eventlog.lst"
        If Dir(strCount) <> "" Then FileCopy(strCount, strBackUp & "eventlog.lst")
        strCount = INI_Settings.sServer & "\eventlog.dcg"
        If Dir(strCount) <> "" Then FileCopy(strCount, strBackUp & "eventlog.dcg")

        strCount = Dir(INI_Settings.sCampaign & "\*.*")
        Do While strCount <> ""   ' Start the loop.
            ' Ignore the current directory and the encompassing directory.
            If strCount <> "." And strCount <> ".." Then
                ' Use bitwise comparison to make sure MyName is a directory.

                FileCopy(INI_Settings.sCampaign & "\" & strCount, strBackUp & strCount)

            End If
            strCount = Dir()   ' Get next entry.
        Loop

    End Sub

    Public Sub FindGrid(ByRef X As Long, _
                        ByRef Y As Long, _
                        ByRef strGrid As String)
        Dim lngX As Long
        Dim lngY As Long
        Dim strX As String
        Dim strY As String
        lngY = Int((Y / 10 ^ 4) + 1)
        strY = Format(lngY, "0")
        lngX = Int(X / 10 ^ 4)
        strX = Chr(lngX Mod 26 + 65)
        lngX = Int(lngX / 26)
        strX = Chr(lngX + 65) & strX
        strGrid = strX & "-" & strY
    End Sub
    Public Sub LoadStructFile(ByRef bolerror As Boolean, _
                            ByRef strerror As String, _
                            ByRef StructInfo() As Building, _
                            ByRef StructList(,) As String, _
                            ByRef ini_settings As INI_Class)

        Dim strStructFile As String
        Dim strInput As String
        Dim strValue As String
        Dim intPos As Integer
        Dim intStart As Integer
        Dim intList As Integer
        Dim filereader As IO.StreamReader
        strStructFile = ini_settings.sData & "structures.dcg"
        If Dir(strStructFile) = "" Then
            bolerror = True
            strerror = "Cannot find structure file!"
            Exit Sub
        End If
        If My.Computer.FileSystem.FileExists(strStructFile) Then
            filereader = My.Computer.FileSystem.OpenTextFileReader(strStructFile)
            Do Until filereader.EndOfStream
                strInput = filereader.ReadLine
                intStart = InStr(strInput, "[")
                intPos = InStr(strInput, "]")
                If intStart > 0 And intPos > 0 And intPos > intStart Then
                    intStart = intStart + 1
                    strValue = Trim(Mid(strInput, intStart, intPos - intStart))
                    ReDim Preserve StructInfo(StructInfo.Length)
                    ReDim Preserve StructList(10, StructInfo.Length - 1)
                    StructInfo(StructInfo.Length - 1).Unit = strValue
                    intList = 0
                Else
                    If StructInfo.Length > 1 Then
                        intStart = InStr(strInput, "Fuel=")
                        If intStart > 0 Then
                            intPos = InStr(strInput, "=") + 1
                            StructInfo(StructInfo.Length - 1).Fuel = Int(Val(Mid(strInput, intPos)))
                        End If
                        intStart = InStr(strInput, "Supply=")
                        If intStart > 0 Then
                            intPos = InStr(strInput, "=") + 1
                            StructInfo(StructInfo.Length - 1).Supply = Int(Val(Mid(strInput, intPos)))
                        End If
                        intStart = InStr(strInput, "Troops=")
                        If intStart > 0 Then
                            intPos = InStr(strInput, "=") + 1
                            StructInfo(StructInfo.Length - 1).Troops = Int(Val(Mid(strInput, intPos)))
                        End If
                        intStart = InStr(strInput, "Cols=")
                        If intStart > 0 Then
                            intPos = InStr(strInput, "=") + 1
                            StructInfo(StructInfo.Length - 1).Cols = Int(Val(Mid(strInput, intPos)))
                        End If
                        intStart = InStr(strInput, "Alive=")
                        If intStart > 0 Then
                            intPos = InStr(strInput, "=") + 1
                            StructInfo(StructInfo.Length - 1).Alive = Trim(Mid(strInput, intPos))
                        End If
                        intStart = InStr(strInput, "Dead=")
                        If intStart > 0 Then
                            intPos = InStr(strInput, "=") + 1
                            StructInfo(StructInfo.Length - 1).Dead = Trim(Mid(strInput, intPos))
                        End If
                        intStart = InStr(strInput, "Repair=")
                        If intStart > 0 Then
                            intPos = InStr(strInput, "=") + 1
                            StructInfo(StructInfo.Length - 1).Repair = Int(Val(Mid(strInput, intPos)))
                        End If
                        intStart = InStr(strInput, "vehicles.stationary.Stationary")
                        If intStart > 0 Then
                            intList = intList + 1
                            If intList > 10 Then
                                intList = 10
                            Else
                                StructInfo(StructInfo.Length - 1).Size = intList
                                StructList(intList, StructInfo.Length - 1) = Trim(strInput)
                            End If
                        End If

                    End If
                End If
            Loop
            filereader.Close()
        End If
    End Sub


    Public Sub LoadFactFile(ByRef bolerror As Boolean, _
                            ByRef strerror As String, _
                            ByRef StructInfo() As Building, _
                            ByRef Fact() As Factory, _
                            ByRef Locat() As Location, _
                            ByRef strDebrief() As String, _
                            ByRef INI_Settings As INI_Class)

        Dim strFactFile As String
        Dim strInput As String
        Dim intPos As Integer
        Dim intStart As Integer
        Dim filereader As IO.StreamReader
        strFactFile = INI_Settings.sCampaign & "\factory.dcg"
        If Dir(strFactFile) = "" Then
            bolerror = True
            strerror = "Cannot find Factory file!"
            Exit Sub
        End If
        If My.Computer.FileSystem.FileExists(strFactFile) Then
            filereader = My.Computer.FileSystem.OpenTextFileReader(strFactFile)
            Do Until filereader.EndOfStream
                strInput = filereader.ReadLine
                intStart = InStr(strInput, "_fact")
                If intStart > 0 Then
                    ReDim Preserve Fact(Fact.Length)
                    Fact(Fact.Length - 1).Active = True
                    strInput = Trim(strInput)
                    If Left(strInput, 1) = "X" Then
                        Fact(Fact.Length - 1).Active = False
                        intStart = 3
                    Else
                        Fact(Fact.Length - 1).Active = True
                        intStart = 1
                    End If
                    intPos = InStr(intStart, strInput, " ")
                    Fact(Fact.Length - 1).ID = Trim(Mid(strInput, intStart, intPos - intStart))
                    intStart = intPos + 1
                    intPos = InStr(intStart, strInput, " ")
                    Fact(Fact.Length - 1).Unit = Trim(Mid(strInput, intStart, intPos - intStart))
                    intStart = intPos + 1
                    intPos = InStr(intStart, strInput, " ")
                    Fact(Fact.Length - 1).Side = Int(Val(Mid(strInput, intStart, intPos - intStart)))
                    intStart = intPos + 1
                    intPos = InStr(intStart, strInput, " ")
                    Fact(Fact.Length - 1).X = Val(Mid(strInput, intStart, intPos - intStart))
                    intStart = intPos + 1
                    intPos = InStr(intStart, strInput, " ")
                    Fact(Fact.Length - 1).Y = Val(Mid(strInput, intStart, intPos - intStart))
                    intStart = intPos + 1
                    Fact(Fact.Length - 1).Head = Int(Val(Mid(strInput, intStart)))
                    FindStructure(bolerror, _
                                    strerror, _
                                    Fact(Fact.Length - 1).Unit, _
                                    Fact(Fact.Length - 1).Struct, _
                                    StructInfo)
                    If Fact(Fact.Length - 1).Struct < 1 Then

                        ReDim Preserve strDebrief(strDebrief.Length)
                        strDebrief(strDebrief.Length - 1) = "Possible error - cannot find Structure " & _
                                Fact(Fact.Length - 1).ID & " " & Fact(Fact.Length - 1).Unit
                    Else
                        Fact(Fact.Length - 1).Fuel = StructInfo(Fact(Fact.Length - 1).Struct).Fuel
                        Fact(Fact.Length - 1).Supply = StructInfo(Fact(Fact.Length - 1).Struct).Supply
                        Fact(Fact.Length - 1).Troops = StructInfo(Fact(Fact.Length - 1).Struct).Troops
                        Fact(Fact.Length - 1).Col = StructInfo(Fact(Fact.Length - 1).Struct).Cols
                        Fact(Fact.Length - 1).Size = StructInfo(Fact(Fact.Length - 1).Struct).Size
                        Fact(Fact.Length - 1).Curr = StructInfo(Fact(Fact.Length - 1).Struct).Size
                        Fact(Fact.Length - 1).Repair = StructInfo(Fact(Fact.Length - 1).Struct).Repair
                        FindWayPoint(Fact(Fact.Length - 1).X, _
                                    Fact(Fact.Length - 1).Y, _
                                    Fact(Fact.Length - 1).Loc, _
                                    Fact(Fact.Length - 1).intLoc, _
                                    Locat)
                        Locat(Fact(Fact.Length - 1).intLoc).MaxFuel = Locat(Fact(Fact.Length - 1).intLoc).MaxFuel + Fact(Fact.Length - 1).Fuel
                        Locat(Fact(Fact.Length - 1).intLoc).MaxSup = Locat(Fact(Fact.Length - 1).intLoc).MaxSup + Fact(Fact.Length - 1).Supply
                        Locat(Fact(Fact.Length - 1).intLoc).MaxTroops = Locat(Fact(Fact.Length - 1).intLoc).MaxTroops + Fact(Fact.Length - 1).Troops
                    End If
                End If
            Loop
            filereader.Close()
        End If
    End Sub

    Public Sub GenFactFile(ByRef bolerror As Boolean, _
                            ByRef strerror As String, _
                            ByRef Fact() As Factory, _
                            ByRef INI_Settings As INI_Class)
        Dim intLine As Integer
        Dim strOutput As String
        Dim sb As New StringBuilder
        sb.AppendLine("[Factory]")
        For intLine = Fact.Length - 1 To 1 Step -1
            With Fact(intLine)
                If .Active Then
                    strOutput = "  "
                Else
                    strOutput = "X "
                End If
                sb.AppendLine(strOutput & .ID & " " & _
                        .Unit & " " & _
                        Format(.Side, "0") & " " & _
                        Format(.X, "0.00") & " " & _
                        Format(.Y, "0.00") & " " & _
                        Format(.Head, "0.00"))
            End With
        Next

        Using outfile As New StreamWriter(INI_Settings.sCampaign & "\factory.dcg")
            outfile.Write(sb.ToString())
            outfile.Close()
        End Using
    End Sub

    Public Sub FindStructure(ByRef bolerror As Boolean, _
                    ByRef strerror As String, _
                    ByRef Unit As String, _
                    ByRef Struct As Integer, _
                    ByRef StructInfo() As Building)
        Dim intCount As Integer
        If StructInfo.Length < 2 Then
            Struct = 0
            Exit Sub
        End If
        For intCount = StructInfo.Length - 1 To 1 Step -1
            If Unit = StructInfo(intCount).Unit Then
                Struct = intCount
                Exit For
            End If
        Next
    End Sub

    Public Sub PlaceFactStat(ByRef intFact As Integer, _
                                ByRef sb As StringBuilder, _
                                ByRef StructInfo() As Building, _
                                ByRef StructList(,) As String, _
                                ByRef Fact() As Factory)
        Dim strOutput As String
        Dim intCount As Integer
        With Fact(intFact)
            If .Active Then
                If InStr(StructInfo(.Struct).Alive, "vehicles.stationary") > 0 Then
                    strOutput = "  " & .ID & "1 " & _
                            StructInfo(.Struct).Alive & " " & _
                            "0 " & _
                            Format(.X, "0.00") & " " & _
                            Format(.Y, "0.00") & " " & _
                            Format(.Head, "0.00")
                    sb.AppendLine(strOutput)
                End If
                For intCount = 1 To .Size
                    strOutput = "  " & .ID & Format(intCount + 1, "0") & " " & _
                        StructList(intCount, .Struct) & " " & _
                        Format(.Side, "0") & " " & _
                        Format(.X, "0.00") & " " & _
                        Format(.Y, "0.00") & " " & _
                        Format(.Head, "0.00")
                    sb.AppendLine(strOutput)
                Next
            Else
                If InStr(StructInfo(.Struct).Dead, "vehicles.stationary") > 0 Then
                    strOutput = "  " & .ID & "1 " & _
                            StructInfo(.Struct).Dead & " " & _
                            "0 " & _
                            Format(.X, "0.00") & " " & _
                            Format(.Y, "0.00") & " " & _
                            Format(.Head, "0.00")
                    sb.AppendLine(strOutput)
                End If
            End If
        End With
    End Sub

    Public Sub CleanUpFact(ByRef bolerror As Boolean, _
                        ByRef strerror As String, _
                        ByRef Fact() As Factory, _
                        ByRef Locat() As Location)
        'This sub does a final check on factory objects and sets the correct side
        Dim intFactCnt As Integer
        If Fact.Length < 2 Then
            bolerror = True
            strerror = "Could not find Factories in -CleanUpFact-"
            Exit Sub
        End If
        For intFactCnt = 1 To Fact.Length - 1
            With Fact(intFactCnt)
                If Locat(.intLoc).Side <> 0 Then
                    .Side = Locat(.intLoc).Side
                End If
            End With
        Next
    End Sub

    Public Sub Findfact(ByRef strID As String, _
                            ByRef intFact As Integer, _
                            ByRef Fact() As Factory)
        If Fact.Length < 2 Then
            intFact = 0
            Exit Sub
        End If
        For intFact = Fact.Length - 1 To 1 Step -1
            If strID = Fact(intFact).ID Then
                Exit For
            End If
        Next
    End Sub

    Public Sub FindStation(ByRef strLoc As String, _
                        ByRef intLoc As Integer, _
                        ByRef iTot As Integer, _
                        ByRef Station() As Location)
        If iTot < 1 Then
            intLoc = 0
            Exit Sub
        End If
        For intLoc = iTot To 0 Step -1
            If Station(intLoc).Loc = strLoc Then
                Exit For
            End If
        Next

    End Sub
    Public Sub FindHarbor(ByRef strLoc As String, _
                        ByRef intLoc As Integer, _
                        ByRef iTot As Integer, _
                        ByRef Harbor() As Location)
        If iTot < 1 Then
            intLoc = 0
            Exit Sub
        End If
        For intLoc = iTot To 0 Step -1
            If Harbor(intLoc).Loc = strLoc Then
                Exit For
            End If
        Next

    End Sub

    Public Sub LoadChiefShip(ByVal sInput As String, _
                                ByRef BornPlace() As BornPlaceClass, _
                                ByRef ConvoyInfo() As Convoy, _
                                ByRef Ship() As Column, _
                                ByRef Harbor() As Location, _
                                ByRef INI_Settings As INI_Class)
        Dim intCon As Integer
        Dim i As Integer
        Dim s As String
        'This sub loads the ships from shipumns.dcg file ito the ship array



        ReDim Preserve Ship(Ship.Length)
        Dim sShips() As String
        sInput = sInput.Trim
        sShips = sInput.Split(" ")
        With Ship(Ship.Length - 1)
            .Size = 1
            .Curr = 1
            .OrigSize = 1
            .Direction = 1
            .Hold = False
            For i = 0 To sShips.Length - 1
                If i = 0 Then .Ident = sShips(i)
                If i = 1 Then
                    .Unit = sShips(i)
                    FindCon(Ship(Ship.Length - 1).Unit, _
                    intCon, _
                    ConvoyInfo)
                    If intCon > 0 Then
                        .Size = ConvoyInfo(intCon).Size
                        .Curr = ConvoyInfo(intCon).Size
                        .OrigSize = ConvoyInfo(intCon).Size
                        .Columns = ConvoyInfo(intCon).Columns
                        .Supply = ConvoyInfo(intCon).Supply
                        .Fuel = ConvoyInfo(intCon).Fuel
                        .Troops = ConvoyInfo(intCon).Troops
                        .Carrier = ConvoyInfo(intCon).Carrier
                        .ConType = intCon
                        .MultUnit = ConvoyInfo(intCon).MultUnits
                    End If
                End If
                If i = 2 Then .Side = Int(Val(sShips(i)))
                If i = 3 Then .ROF = sShips(i)
                If i = 4 Or i = 5 Then .ROF &= " " & sShips(i)
                If i = 6 Then .sFrom = sShips(i).Replace("@", "")
                If i = 7 Then .sTo = sShips(i).Replace("@", "")
                If i = 8 Then .Orig = sShips(i).Replace("$", "")
                If i > 8 Then
                    If sShips(i).Contains("D=") Then
                        s = sShips(i).Replace("D=", "")
                        .Direction = Int(Val(s))
                    End If

                    If sShips(i).Contains("S=") Then
                        s = sShips(i).Replace("S=", "")
                        .Size = Int(Val(s))
                        .Curr = Int(Val(s))
                    End If
                End If

            Next
            FindHarbor(.sFrom, _
                   .iFrom, _
                   Harbor.Length - 1, _
                   Harbor)
            If .sFrom <> "" Then
                FindHarbor(.sTo, _
                           .iTo, _
                           Harbor.Length - 1, _
                           Harbor)
                If .iTo < 0 Or .iFrom < 0 Then
                    If .sTo <> .sFrom Then
                        .sTo = "Blank"
                        .sFrom = "Blank"
                        .iTo = -1
                        .iFrom = -1
                    End If
                End If
            Else
                .sTo = "Blank"
                .sFrom = "Blank"
                .iTo = -1
                .iFrom = -1
            End If
            
        End With
        'Add Carrier to BP
        If Ship(Ship.Length - 1).Carrier > 0 Then
            ReDim Preserve BornPlace(BornPlace.Length)
            With BornPlace(BornPlace.Length - 1)
                .Loc = Ship(Ship.Length - 1).Ident
                .intLoc = (Ship.Length - 1) * -1
                .Side = Ship(Ship.Length - 1).Side
                .X = 0
                .Y = 0
                .R = Int(INI_Settings.BornPlaceRadius * 2)
                If Ship(Ship.Length - 1).Curr >= Ship(Ship.Length - 1).Carrier Then
                    .Active = True
                Else
                    .Active = False
                End If
            End With
        End If
        
    End Sub

    Public Sub LoadChiefTrain(ByVal sInput As String, _
                                ByRef ConvoyInfo() As Convoy, _
                                ByRef Train() As Column, _
                                ByRef Station() As Location)
        Dim intCon As Integer
        Dim i As Integer
        Dim s As String
        'This sub loads the trains from the trainumns.dcg file ito the train array



        ReDim Preserve Train(Train.Length)
        Dim sTrains() As String
        sInput.Trim()
        sTrains = sInput.Split(" ")
        With Train(Train.Length - 1)
            .Size = 1
            .OrigSize = 1
            .Curr = 1
            .Direction = 1
            .Hold = False
            For i = 0 To sTrains.Length - 1
                If i = 0 Then .Ident = sTrains(i)
                If i = 1 Then
                    .Unit = sTrains(i)
                    FindCon(.Unit, _
                    intCon, _
                    ConvoyInfo)
                    If intCon > 0 Then
                        .Size = ConvoyInfo(intCon).Size
                        .Curr = ConvoyInfo(intCon).Size
                        .OrigSize = ConvoyInfo(intCon).Size
                        .Columns = ConvoyInfo(intCon).Columns
                        .Supply = ConvoyInfo(intCon).Supply
                        .Fuel = ConvoyInfo(intCon).Fuel
                        .Troops = ConvoyInfo(intCon).Troops
                        .ConType = intCon
                        .MultUnit = ConvoyInfo(intCon).MultUnits
                    End If
                End If
                If i = 2 Then .Side = Int(Val(sTrains(i)))
                If i = 3 Then .sFrom = sTrains(i).Replace("@", "")
                If i = 4 Then .sTo = sTrains(i).Replace("@", "")
                If i = 5 Then .Orig = sTrains(i).Replace("$", "")
                If i > 5 Then
                    If sTrains(i).Contains("D=") Then
                        s = sTrains(i).Replace("D=", "")
                        .Direction = Int(Val(s))
                    End If
                    If sTrains(i).Contains("S=") Then
                        s = sTrains(i).Replace("S=", "")
                        .Size = Int(Val(s))
                        .Curr = Int(Val(s))
                    End If
                End If
            Next
            FindStation(.sFrom, _
                    .iFrom, Station.Length - 1, _
                    Station)
            If .sFrom <> "" Then
                FindStation(.sTo, _
                            .iTo, Station.Length - 1, _
                            Station)
                If .iTo < 0 Or .iFrom < 0 Then
                    If .sTo <> .sFrom Then
                        .sTo = "Blank"
                        .sFrom = "Blank"
                        .iTo = -1
                        .iFrom = -1
                    End If
                End If
            Else
                .sTo = "Blank"
                .sFrom = "Blank"
                .iTo = -1
                .iFrom = -1
            End If
        End With

        


    End Sub

    Public Sub LoadChiefColumn(ByVal sInput As String, _
                                ByRef ConvoyInfo() As Convoy, _
                                ByRef Col() As Column, _
                                ByRef Locat() As Location)
        Dim intPos As Integer
        Dim intStart As Integer
        Dim intCon As Integer
        Dim i As Integer
        Dim s As String
        'This sub loads the car/tank columns from the columns.dcg file ito the column array
        ReDim Preserve Col(Col.Length)
        Dim sColumns() As String
        sInput.Trim()
        sColumns = sInput.Split(" ")
        With Col(Col.Length - 1)
            .Direction = 1
            .Size = 1
            .Curr = 1
            .OrigSize = 1
            .AllowLoad = 1
            .Hold = False
            For i = 0 To sColumns.Length - 1
                If i = 0 Then .Ident = sColumns(i)
                If i = 1 Then
                    .Unit = sColumns(i)
                    If InStr(.Unit, "Armor.") > 0 Then intStart = 7
                    If InStr(.Unit, "Infantry.") > 0 Then intStart = 10
                    If intStart > 0 Then
                        intPos = InStr(.Unit, "-")
                        .Size = Val(Mid(Col(Col.Length - 1).Unit, intStart, intPos - intStart))
                        .Curr = Col(Col.Length - 1).Size
                        .Troops = Col(Col.Length - 1).Size
                        .OrigSize = 1
                        intPos = InStr(Col(Col.Length - 1).Orig, "-")
                        If intPos > 0 Then
                            .OrigSize = Int(Val(Left(.Orig, intPos - 1)))
                        End If
                    Else
                        FindCon(.Unit, _
                                    intCon, _
                                    ConvoyInfo)
                        If intCon < 1 Then
                            .Size = 1
                            .Curr = 1
                            .OrigSize = 1
                            If intPos > 0 Then
                                .OrigSize = Int(Val(Left(.Orig, intPos - 1)))
                            End If
                        Else
                            .Size = ConvoyInfo(intCon).Size
                            .Curr = ConvoyInfo(intCon).Size
                            .OrigSize = ConvoyInfo(intCon).Size
                            .Columns = ConvoyInfo(intCon).Columns
                            .Supply = ConvoyInfo(intCon).Supply
                            .Fuel = ConvoyInfo(intCon).Fuel
                            .Troops = ConvoyInfo(intCon).Troops
                            .Artillery = ConvoyInfo(intCon).Artillery
                            .Amp = ConvoyInfo(intCon).Amp
                            .BR = ConvoyInfo(intCon).BR
                            .Armor = ConvoyInfo(intCon).Armor
                            .ConType = intCon
                            .MultUnit = ConvoyInfo(intCon).MultUnits
                        End If
                    End If
                End If
                If i = 2 Then .Side = Int(Val(sColumns(i)))
                If i = 3 Then .sFrom = sColumns(i).Replace("@", "")
                If i = 4 Then .sTo = sColumns(i).Replace("@", "")
                If i = 5 Then .Orig = sColumns(i).Replace("$", "")
                If i > 5 Then
                    If sColumns(i).Contains("D=") Then
                        s = sColumns(i).Replace("D=", "")
                        .Direction = Int(Val(s))
                    End If
                    If sColumns(i).Contains("S=") Then
                        s = sColumns(i).Replace("S=", "")
                        .Size = Int(Val(s))
                        .Curr = Int(Val(s))
                    End If
                    If sColumns(i).Contains("LOAD=") Then
                        s = sColumns(i).Replace("LOAD=", "")
                        .AllowLoad = Int(Val(s))
                    End If
                End If
            Next
            FindLoc(.sFrom, _
                .iFrom, _
                Locat.Length - 1, _
                Locat)
            If Col(Col.Length - 1).sFrom <> "" Then
                FindLoc(.sTo, _
                        .iTo, _
                        Locat.Length - 1, _
                        Locat)
                If .iTo < 0 Or .iFrom < 0 Then
                    If .sTo <> .sFrom Then
                        .sTo = "Blank"
                        .sFrom = "Blank"
                        .iTo = -1
                        .iFrom = -1
                    End If
                End If
            Else
                .sTo = "Blank"
                .sFrom = "Blank"
                .iTo = -1
                .iFrom = -1
            End If
        End With
    End Sub

    Public Sub FindTrain(ByRef strID As String, _
                        ByRef intChief As Integer, _
                        ByRef Train() As Column)
        If Train.Length > 1 Then
            For intChief = Train.Length - 1 To 1 Step -1
                If strID = Train(intChief).Ident Then
                    Exit For
                End If
            Next
        Else
            intChief = 0
        End If
    End Sub
    Public Sub FindShip(ByRef strID As String, _
                            ByRef intChief As Integer, _
                            ByRef Ship() As Column)
        If Ship.Length > 1 Then
            For intChief = Ship.Length - 1 To 1 Step -1
                If strID = Ship(intChief).Ident Then
                    Exit For
                End If
            Next
        Else
            intChief = 0
        End If
    End Sub

    Public Sub CheckShips(ByRef bolerror As Boolean, _
                            ByRef strerror As String, _
                            ByRef MissSettings As Mission, _
                            ByRef Col() As Column, _
                            ByRef Ship() As Column, _
                            ByRef Harbor() As Location, _
                            ByRef strDebrief() As String)
        'Checks the ships to see if any have been destroyed
        Dim intCount As Integer
        Dim intStart As Integer
        Dim intCntCol As Integer
        Dim strUnit As String = ""
        Dim strOutput As String = ""
        For intCount = 1 To Ship.Length - 1

            With Ship(intCount)
                If .Curr > 0 Then
                    If .Curr / .Size <= MissSettings.Convoy Then
                        .Curr = 0
                    End If
                End If

                If .Curr < 1 Then
                    intStart = InStr(.Unit, ".") + 1
                    strUnit = Mid(.Unit, intStart)
                    FindGrid(Harbor(.iFrom).X, Harbor(.iFrom).Y, strOutput)

                    ReDim Preserve strDebrief(strDebrief.Length)
                    strDebrief(strDebrief.Length - 1) = strUnit & " at " & .sFrom & strOutput
                    .sFrom = "Destroyed"
                    .sTo = "Destroyed"
                    .iFrom = 0
                    .iTo = 0
                    .Curr = .Size
                    RestoreOrigCol(.Unit, .Orig)
                    If .Columns > 0 Then
                        For intCntCol = 1 To Col.Length - 1
                            If Col(intCntCol).sFrom = .Ident Then
                                Col(intCntCol).sFrom = "Destroyed"
                                Col(intCntCol).sTo = "Destroyed"
                                Col(intCntCol).iFrom = 0
                                Col(intCntCol).iTo = 0
                                RestoreOrigCol(Col(intCntCol).Unit, Col(intCntCol).Orig)
                            End If
                        Next
                    End If
                End If
            End With
        Next
    End Sub

    Public Sub CheckTrains(ByRef bolerror As Boolean, _
                            ByRef strerror As String, _
                            ByRef MissSettings As Mission, _
                            ByRef Col() As Column, _
                            ByRef Train() As Column, _
                            ByRef Station() As Location, _
                            ByRef strDebrief() As String)
        'Checks the ships to see if any have been destroyed
        Dim intCount As Integer
        Dim intStart As Integer
        Dim intCntCol As Integer
        Dim strUnit As String = ""
        Dim strOutput As String = ""
        For intCount = 1 To Train.Length - 1

            With Train(intCount)
                If .Curr > 0 Then
                    If .Curr / .Size <= MissSettings.Convoy Then
                        .Curr = 0
                    End If
                End If

                If .Curr < 1 Then
                    intStart = InStr(.Unit, ".") + 1
                    strUnit = Mid(.Unit, intStart)
                    FindGrid(Station(.iFrom).X, Station(.iFrom).Y, strOutput)

                    ReDim Preserve strDebrief(strDebrief.Length)
                    strDebrief(strDebrief.Length - 1) = strUnit & " at " & .sFrom & strOutput
                    .sFrom = "Destroyed"
                    .sTo = "Destroyed"
                    .iFrom = 0
                    .iTo = 0
                    .Curr = .Size
                    RestoreOrigCol(.Unit, .Orig)
                    If .Columns > 0 Then
                        For intCntCol = 1 To Col.Length - 1
                            If Col(intCntCol).sFrom = .Ident Then
                                Col(intCntCol).sFrom = "Destroyed"
                                Col(intCntCol).sTo = "Destroyed"
                                Col(intCntCol).iFrom = 0
                                Col(intCntCol).iTo = 0
                                RestoreOrigCol(Col(intCntCol).Unit, Col(intCntCol).Orig)
                            End If
                        Next
                    End If
                End If
            End With
        Next
    End Sub

    Public Sub MoveShips(ByRef bolerror As Boolean, _
                            ByRef strerror As String, _
                            ByRef Ship() As Column)
        Dim intCount As Integer
        If Ship.Length < 2 Then Exit Sub
        For intCount = 1 To Ship.Length - 1
            With Ship(intCount)
                .sFrom = .sTo
                .iFrom = .iTo
            End With
        Next
    End Sub

    Public Sub MoveTrains(ByRef bolerror As Boolean, _
                                ByRef strerror As String, _
                                ByRef Bridge() As Brid, _
                                ByRef Train() As Column, _
                                ByRef strDebrief() As String)
        Dim intCount As Integer
        Dim intCnt2 As Integer
        Dim strOutput As String
        Dim intStart As Integer
        If Train.Length < 2 Then Exit Sub
        If Bridge.Length > 1 Then
            For intCount = 1 To Bridge.Length - 1
                For intCnt2 = 1 To Train.Length - 1
                    With Train(intCnt2)
                        If (.sFrom = Bridge(intCount).sTo And _
                                .sTo = Bridge(intCount).sFrom) Or _
                                (.sTo = Bridge(intCount).sTo And _
                                .sFrom = Bridge(intCount).sFrom) Then
                            .sTo = .sFrom
                            .iTo = .iFrom

                            ReDim Preserve strDebrief(strDebrief.Length)
                            intStart = InStr(.Unit, ".") + 1
                            strOutput = Mid(.Unit, intStart)
                            strOutput = strOutput & " delayed by " & Bridge(Bridge.Length - 1).ID
                            strDebrief(strDebrief.Length - 1) = strOutput
                        End If
                    End With
                Next
            Next
        End If

        For intCount = 1 To Train.Length - 1
            With Train(intCount)
                .sFrom = .sTo
                .iFrom = .iTo
            End With
        Next
    End Sub

    Public Sub LocateRailBridge(ByRef strLine As String, _
                            ByRef strID As String, _
                            ByRef Bridge() As Brid, _
                            ByRef camsettings As Campaign, _
                            ByRef MissSettings As Mission, _
                            ByRef Station() As Location, _
                            ByRef ini_settings As INI_Class)
        Dim strFrom As String = ""
        Dim strTo As String = ""
        Dim dblX As Double
        Dim dblY As Double
        Dim intBridge As Integer
        Dim strCoor As String = ""
        Dim dblBridgeX As Double
        Dim dblBridgeY As Double
        Dim iH As Integer
        Dim dblDist As Double
        Dim intCount As Integer
        Dim strInput As String = ""
        Dim strValue As String = ""
        Dim intStart As Integer
        Dim intPos As Integer
        Dim strRLSFile As String = ""
        Dim lngCount As Long
        Dim sWP(0) As String
        Dim totWP As Integer
        Dim sInput As String = ""
        Dim filereader As IO.StreamReader
        If Bridge.Length > 1 Then
            For intCount = 1 To Bridge.Length - 1
                If Bridge(intCount).ID = strID Then Exit Sub
            Next
        End If
        intStart = InStr(strLine, " at ")
        If intStart > 1 Then
            intStart = intStart + 4
            strCoor = Mid(strLine, intStart)
            FindCoor(strCoor, dblBridgeX, dblBridgeY, iH)
            strRLSFile = ini_settings.sData & camsettings.RouteName & ".rls"
            If Dir(strRLSFile) = "" Then Exit Sub
            If My.Computer.FileSystem.FileExists(strRLSFile) Then
                filereader = My.Computer.FileSystem.OpenTextFileReader(strRLSFile)
                Do Until filereader.EndOfStream
                    sInput = Trim(filereader.ReadLine)
                    If sInput <> "" Then
                        totWP = totWP + 1
                        ReDim Preserve sWP(totWP)
                        sWP(totWP) = sInput
                    End If
                Loop
                filereader.Close()
            End If
            If totWP < 1 Then
                Exit Sub
            End If
            For lngCount = 1 To totWP

                strInput = sWP(lngCount)
                intStart = InStr(strInput, "[")
                If intStart > 0 Then
                    'find start location
                    intStart = intStart + 1
                    intPos = InStr(strInput, " to ")
                    strValue = Trim(Mid(strInput, intStart, intPos - intStart))
                    strFrom = strValue
                    intStart = intPos + 4
                    intPos = InStr(strInput, "]")
                    strValue = Trim(Mid(strInput, intStart, intPos - intStart))
                    strTo = strValue

                Else
                    If strInput <> "" Then FindCoor(strInput, _
                                            dblX, _
                                            dblY, _
                                            iH)
                    dblDist = Math.Sqrt(((dblBridgeX - dblX) ^ 2) + ((dblBridgeY - dblY) ^ 2))
                    If dblDist < 500 Then
                        FindRailBridge(strID, _
                                       strFrom, _
                                       strTo, _
                                       dblX, _
                                       dblY, _
                                       intBridge, _
                                       Bridge, _
                                       Station)
                        If intBridge = Bridge.Length - 1 And MissSettings.Bridge > 1 Then
                            DestroyBridges(intBridge, _
                                           Bridge)
                        End If
                    End If
                End If

            Next
        End If
    End Sub
    Public Sub UnLoadShip(ByRef bolerror As Boolean, _
                            ByRef strerror As String, _
                            ByRef camsettings As Campaign, _
                            ByRef Col() As Column, _
                            ByRef Ship() As Column, _
                            ByRef Infantry() As Column, _
                            ByRef Locat() As Location, _
                            ByRef Harbor() As Location, _
                            ByRef RouteStart(,) As Integer, _
                            ByRef ColLoc() As String)

        Dim intShip As Integer
        Dim intTank As Integer
        Dim strTest As String
        Dim i As Integer
        'This sub removes tanks from a train or ship
        If Ship.Length < 2 Then Exit Sub
        For intShip = 1 To Ship.Length - 1
            With Ship(intShip)

                strTest = .sFrom
                If .iFrom > 0 And .Columns > 0 Then
                    'Forced Unloads
                    If Not .sFrom.Contains("_Sea") Then
                        If Col.Length > 1 Then
                            For intTank = 1 To Col.Length - 1
                                If Col(intTank).sFrom = .Ident And Col(intTank).AllowLoad < 1 Then
                                    Col(intTank).sFrom = Harbor(.iFrom).Road
                                    Col(intTank).sTo = Harbor(.iFrom).Road
                                    Col(intTank).iFrom = Harbor(.iFrom).intRoad
                                    Col(intTank).iTo = Harbor(.iFrom).intRoad
                                    If colloc.length > 1 Then
                                        For i = 1 To ColLoc.Length - 1
                                            Dim sArray() As String
                                            sArray = ColLoc(i).Split(" ")
                                            If sArray(0) = Col(intTank).Ident Then
                                                ColLoc(i) = Col(intTank).Ident & " " & Col(intTank).sFrom
                                                Exit For
                                            End If
                                        Next
                                    End If
                                End If
                            Next
                        End If
                        If Infantry.Length > 1 Then
                            For intTank = 1 To Infantry.Length - 1
                                If Infantry(intTank).sFrom = .Ident And Infantry(intTank).AllowLoad < 1 Then
                                    Infantry(intTank).sFrom = Harbor(.iFrom).Road
                                    Infantry(intTank).sTo = Harbor(.iFrom).Road
                                    Infantry(intTank).iFrom = Harbor(.iFrom).intRoad
                                    Infantry(intTank).iTo = Harbor(.iFrom).intRoad
                                    If ColLoc.Length > 1 Then
                                        For i = 1 To ColLoc.Length - 1
                                            Dim sArray() As String
                                            sArray = ColLoc(i).Split(" ")
                                            If sArray(0) = Infantry(intTank).Ident Then
                                                ColLoc(i) = Infantry(intTank).Ident & " " & Infantry(intTank).sFrom
                                                Exit For
                                            End If
                                        Next
                                    End If
                                End If
                            Next
                        End If
                    End If
                    'Normal Unloads
                    If (Locat(Harbor(.iFrom).intRoad).Side <> .Side And _
                        InStr(.sFrom, "_Sea") = 0) Or _
                        (InStr(.sFrom, "_Beachhead") > 0) Or _
                        (Harbor(.iFrom).Loc = camsettings.RuNavalStop And _
                        .Side = 1) Or _
                        (Harbor(.iFrom).Loc = camsettings.DeNavalStop And _
                        .Side = 2) Then
                        'remove columns
                        For intTank = 1 To Col.Length - 1
                            If Col(intTank).sFrom = .Ident Then
                                .Hold = True
                                Col(intTank).sFrom = Harbor(.iFrom).Road
                                Col(intTank).sTo = Harbor(.iFrom).Road
                                Col(intTank).iFrom = Harbor(.iFrom).intRoad
                                Col(intTank).iTo = Harbor(.iFrom).intRoad
                                If ColLoc.Length > 1 Then
                                    For i = 1 To ColLoc.Length - 1
                                        Dim sArray() As String
                                        sArray = ColLoc(i).Split(" ")
                                        If sArray(0) = Col(intTank).Ident Then
                                            ColLoc(i) = Col(intTank).Ident & " " & Col(intTank).sFrom
                                            Exit For
                                        End If
                                    Next
                                End If
                                If .Side = 1 Then
                                    If Col(intTank).Troops > 1 Then
                                        Locat(Col(intTank).iFrom).Allied = Locat(Col(intTank).iFrom).Allied + Col(intTank).Troops
                                    Else
                                        If InStr(Col(intTank).Unit, "Armor.") > 0 Or InStr(Col(intTank).Unit, "Infantry.") > 0 Then
                                            Locat(Col(intTank).iFrom).Allied = Locat(Col(intTank).iFrom).Allied + (Col(intTank).Size * ptTank)
                                        Else
                                            Locat(Col(intTank).iFrom).Allied = Locat(Col(intTank).iFrom).Allied + ptCar
                                        End If
                                    End If
                                Else
                                    If Col(intTank).Troops > 1 Then
                                        Locat(Col(intTank).iFrom).Axis = Locat(Col(intTank).iFrom).Axis + Col(intTank).Troops
                                    Else
                                        If InStr(Col(intTank).Unit, "Armor.") > 0 Or InStr(Col(intTank).Unit, "Infantry.") > 0 Then
                                            Locat(Col(intTank).iFrom).Axis = Locat(Col(intTank).iFrom).Axis + (Col(intTank).Size * ptTank)
                                        Else
                                            Locat(Col(intTank).iFrom).Axis = Locat(Col(intTank).iFrom).Axis + ptCar
                                        End If
                                    End If
                                End If
                            End If
                        Next
                        'remove infantry
                        If Infantry.Length > 1 Then
                            For intTank = 1 To Infantry.Length - 1
                                If Infantry(intTank).sFrom = .Ident Then
                                    .Hold = True
                                    Infantry(intTank).sFrom = Harbor(.iFrom).Road
                                    Infantry(intTank).sTo = Harbor(.iFrom).Road
                                    Infantry(intTank).iFrom = Harbor(.iFrom).intRoad
                                    Infantry(intTank).iTo = Harbor(.iFrom).intRoad
                                    If ColLoc.Length > 1 Then
                                        For i = 1 To ColLoc.Length - 1
                                            Dim sArray() As String
                                            sArray = ColLoc(i).Split(" ")
                                            If sArray(0) = Infantry(intTank).Ident Then
                                                ColLoc(i) = Infantry(intTank).Ident & " " & Infantry(intTank).sFrom
                                                Exit For
                                            End If
                                        Next
                                    End If
                                    If .Side = 1 Then
                                        Locat(Infantry(intTank).iFrom).Allied += Infantry(intTank).Size
                                    Else
                                        Locat(Infantry(intTank).iFrom).Axis += Infantry(intTank).Size
                                    End If
                                End If
                            Next
                        End If
                        .Direction = -1
                    End If
                    If .Columns > 0 Then

                        Select Case .Side
                            Case 1
                                If .iFrom = RouteStart(2, 3) Then
                                    'remove columns
                                    For intTank = 1 To Col.Length - 1
                                        If Col(intTank).sFrom = .Ident Then
                                            .Hold = True
                                            Col(intTank).sFrom = Harbor(.iFrom).Road
                                            Col(intTank).sTo = Harbor(.iFrom).Road
                                            Col(intTank).iFrom = Harbor(.iFrom).intRoad
                                            Col(intTank).iTo = Harbor(.iFrom).intRoad
                                            If ColLoc.Length > 1 Then
                                                For i = 1 To ColLoc.Length - 1
                                                    Dim sArray() As String
                                                    sArray = ColLoc(i).Split(" ")
                                                    If sArray(0) = Col(intTank).Ident Then
                                                        ColLoc(i) = Col(intTank).Ident & " " & Col(intTank).sFrom
                                                        Exit For
                                                    End If
                                                Next
                                            End If
                                            If Col(intTank).Troops > 1 Then
                                                Locat(Col(intTank).iFrom).Allied += Col(intTank).Troops
                                            Else
                                                If InStr(Col(intTank).Unit, "Armor.") > 0 Or InStr(Col(intTank).Unit, "Infantry.") > 0 Then
                                                    Locat(Col(intTank).iFrom).Allied += (Col(intTank).Size * ptTank)
                                                Else
                                                    Locat(Col(intTank).iFrom).Allied += ptCar
                                                End If
                                            End If
                                            If ColLoc.Length > 1 Then
                                                For i = 1 To ColLoc.Length - 1
                                                    Dim sArray() As String
                                                    sArray = ColLoc(i).Split(" ")
                                                    If sArray(0) = Col(intTank).Ident Then
                                                        ColLoc(i) = Col(intTank).Ident & " " & Col(intTank).sFrom
                                                        Exit For
                                                    End If
                                                Next
                                            End If
                                        End If
                                    Next
                                    'remove infantry
                                    If Infantry.Length > 1 Then
                                        For intTank = 1 To Infantry.Length - 1
                                            If Infantry(intTank).sFrom = .Ident Then
                                                .Hold = True
                                                Infantry(intTank).sFrom = Harbor(.iFrom).Road
                                                Infantry(intTank).sTo = Harbor(.iFrom).Road
                                                Infantry(intTank).iFrom = Harbor(.iFrom).intRoad
                                                Infantry(intTank).iTo = Harbor(.iFrom).intRoad
                                                Locat(Infantry(intTank).iFrom).Allied += Infantry(intTank).Size
                                                If ColLoc.Length > 1 Then
                                                    For i = 1 To ColLoc.Length - 1
                                                        Dim sArray() As String
                                                        sArray = ColLoc(i).Split(" ")
                                                        If sArray(0) = Infantry(intTank).Ident Then
                                                            ColLoc(i) = Infantry(intTank).Ident & " " & Infantry(intTank).sFrom
                                                            Exit For
                                                        End If
                                                    Next
                                                End If
                                            End If
                                        Next
                                    End If
                                    .Direction = -1
                                End If
                            Case 2
                                If .iFrom = RouteStart(1, 3) Then
                                    'remove columns
                                    For intTank = 1 To Col.Length - 1
                                        If Col(intTank).sFrom = .Ident Then
                                            .Hold = True
                                            Col(intTank).sFrom = Harbor(.iFrom).Road
                                            Col(intTank).sTo = Harbor(.iFrom).Road
                                            Col(intTank).iFrom = Harbor(.iFrom).intRoad
                                            Col(intTank).iTo = Harbor(.iFrom).intRoad
                                            If ColLoc.Length > 1 Then
                                                For i = 1 To ColLoc.Length - 1
                                                    Dim sArray() As String
                                                    sArray = ColLoc(i).Split(" ")
                                                    If sArray(0) = Col(intTank).Ident Then
                                                        ColLoc(i) = Col(intTank).Ident & " " & Col(intTank).sFrom
                                                        Exit For
                                                    End If
                                                Next
                                            End If
                                            If Col(intTank).Troops > 1 Then
                                                Locat(Col(intTank).iFrom).Axis += Col(intTank).Troops
                                            Else
                                                If InStr(Col(intTank).Unit, "Armor.") > 0 Or InStr(Col(intTank).Unit, "Infantry.") > 0 Then
                                                    Locat(Col(intTank).iFrom).Axis += (Col(intTank).Size * ptTank)
                                                Else
                                                    Locat(Col(intTank).iFrom).Axis += ptCar
                                                End If
                                            End If
                                        End If
                                    Next
                                    'remove infantry
                                    If Infantry.Length > 1 Then
                                        For intTank = 1 To Infantry.Length - 1
                                            If Infantry(intTank).sFrom = .Ident Then
                                                .Hold = True
                                                Infantry(intTank).sFrom = Harbor(.iFrom).Road
                                                Infantry(intTank).sTo = Harbor(.iFrom).Road
                                                Infantry(intTank).iFrom = Harbor(.iFrom).intRoad
                                                Infantry(intTank).iTo = Harbor(.iFrom).intRoad
                                                Locat(Infantry(intTank).iFrom).Axis += Infantry(intTank).Size
                                                If ColLoc.Length > 1 Then
                                                    For i = 1 To ColLoc.Length - 1
                                                        Dim sArray() As String
                                                        sArray = ColLoc(i).Split(" ")
                                                        If sArray(0) = Infantry(intTank).Ident Then
                                                            ColLoc(i) = Infantry(intTank).Ident & " " & Infantry(intTank).sFrom
                                                            Exit For
                                                        End If
                                                    Next
                                                End If
                                            End If
                                        Next
                                    End If
                                    .Direction = -1
                                End If
                        End Select
                    End If
                End If
            End With
        Next
    End Sub

    Public Sub UnLoadTrain(ByRef bolerror As Boolean, _
                            ByRef strerror As String, _
                            ByRef Col() As Column, _
                            ByRef Train() As Column, _
                            ByRef Locat() As Location, _
                            ByRef Station() As Location, _
                            ByRef Rail() As Waypoint, _
                            ByRef RouteStart(,) As Integer, _
                            ByRef Infantry() As Column, _
                            ByRef ColLoc() As String)

        Dim intTrain As Integer
        Dim intTank As Integer
        Dim bMove As Boolean
        Dim iTrainRoute As Integer
        Dim strTest As String
        Dim i As Integer
        'This sub removes tanks from a train or ship
        If Train.Length < 2 Then Exit Sub
        For intTrain = 1 To Train.Length - 1
            With Train(intTrain)

                strTest = .sFrom


                If .iFrom > 0 And .Direction > 0 And .Columns > 0 Then
                    'Forced Unloads
                    If .sFrom.Contains("_Station") Then
                        If Col.Length > 1 Then
                            For intTank = 1 To Col.Length - 1
                                If Col(intTank).sFrom = .Ident And Col(intTank).AllowLoad < 1 Then
                                    Col(intTank).sFrom = Station(.iFrom).Road
                                    Col(intTank).sTo = Station(.iFrom).Road
                                    Col(intTank).iFrom = Station(.iFrom).intRoad
                                    Col(intTank).iTo = Station(.iFrom).intRoad
                                    If ColLoc.Length > 1 Then
                                        For i = 1 To ColLoc.Length - 1
                                            Dim sArray() As String
                                            sArray = ColLoc(i).Split(" ")
                                            If sArray(0) = Col(intTank).Ident Then
                                                ColLoc(i) = Col(intTank).Ident & " " & Col(intTank).sFrom
                                                Exit For
                                            End If
                                        Next
                                    End If
                                End If
                            Next
                        End If
                        If Infantry.Length > 1 Then
                            For intTank = 1 To Infantry.Length - 1
                                If Infantry(intTank).sFrom = .Ident And Infantry(intTank).AllowLoad < 1 Then
                                    Infantry(intTank).sFrom = Station(.iFrom).Road
                                    Infantry(intTank).sTo = Station(.iFrom).Road
                                    Infantry(intTank).iFrom = Station(.iFrom).intRoad
                                    Infantry(intTank).iTo = Station(.iFrom).intRoad
                                    If ColLoc.Length > 1 Then
                                        For i = 1 To ColLoc.Length - 1
                                            Dim sArray() As String
                                            sArray = ColLoc(i).Split(" ")
                                            If sArray(0) = Infantry(intTank).Ident Then
                                                ColLoc(i) = Infantry(intTank).Ident & " " & Infantry(intTank).sFrom
                                                Exit For
                                            End If
                                        Next
                                    End If
                                End If
                            Next
                        End If
                    End If
                    'Normal Unloads
                    If .Direction > 0 Then
                        bMove = False
                        For iTrainRoute = 1 To Rail.Length - 1
                            If (.Side = 2 And .iFrom = Rail(iTrainRoute).iFrom) Or _
                                (.Side = 1 And .iFrom = Rail(iTrainRoute).iTo) Then
                                If .Side = 1 Then
                                    If Station(Rail(iTrainRoute).iFrom).Side = .Side Then
                                        bMove = True
                                    End If
                                Else
                                    If Station(Rail(iTrainRoute).iTo).Side = .Side Then
                                        bMove = True
                                    End If
                                End If
                            End If
                        Next
                        If Not bMove Or _
                                (.Side = 1 And .iFrom = RouteStart(2, 2)) Or _
                                (.Side = 2 And .iFrom = RouteStart(1, 2)) Then

                            For intTank = 1 To Col.Length - 1
                                If Col(intTank).sFrom = .Ident Then
                                    .Hold = True
                                    Col(intTank).sFrom = Station(.iFrom).Road
                                    Col(intTank).sTo = Station(.iFrom).Road
                                    Col(intTank).iFrom = Station(.iFrom).intRoad
                                    Col(intTank).iTo = Station(.iFrom).intRoad
                                    If ColLoc.Length > 1 Then
                                        For i = 1 To ColLoc.Length - 1
                                            Dim sArray() As String
                                            sArray = ColLoc(i).Split(" ")
                                            If sArray(0) = Col(intTank).Ident Then
                                                ColLoc(i) = Col(intTank).Ident & " " & Col(intTank).sFrom
                                                Exit For
                                            End If
                                        Next
                                    End If
                                    If .Side = 1 Then
                                        If Col(intTank).Troops > 1 Then
                                            Locat(Col(intTank).iFrom).Allied += Col(intTank).Troops
                                        Else
                                            If InStr(Col(intTank).Unit, "Armor.") > 0 Or InStr(Col(intTank).Unit, "Infantry.") > 0 Then
                                                Locat(Col(intTank).iFrom).Allied += (Col(intTank).Size * ptTank)
                                            Else
                                                Locat(Col(intTank).iFrom).Allied += ptCar
                                            End If
                                        End If
                                    Else
                                        If Col(intTank).Troops > 1 Then
                                            Locat(Col(intTank).iFrom).Axis += Col(intTank).Troops
                                        Else
                                            If InStr(Col(intTank).Unit, "Armor.") > 0 Or InStr(Col(intTank).Unit, "Infantry.") > 0 Then
                                                Locat(Col(intTank).iFrom).Axis += (Col(intTank).Size * ptTank)
                                            Else
                                                Locat(Col(intTank).iFrom).Axis += ptCar
                                            End If
                                        End If
                                    End If
                                End If
                            Next
                            If Infantry.Length > 1 Then
                                For intTank = 1 To Infantry.Length - 1
                                    If Infantry(intTank).sFrom = .Ident Then
                                        .Hold = True
                                        Infantry(intTank).sFrom = Station(.iFrom).Road
                                        Infantry(intTank).sTo = Station(.iFrom).Road
                                        Infantry(intTank).iFrom = Station(.iFrom).intRoad
                                        Infantry(intTank).iTo = Station(.iFrom).intRoad
                                        If ColLoc.Length > 1 Then
                                            For i = 1 To ColLoc.Length - 1
                                                Dim sArray() As String
                                                sArray = ColLoc(i).Split(" ")
                                                If sArray(0) = Infantry(intTank).Ident Then
                                                    ColLoc(i) = Infantry(intTank).Ident & " " & Infantry(intTank).sFrom
                                                    Exit For
                                                End If
                                            Next
                                        End If
                                        If .Side = 1 Then
                                            Locat(Infantry(intTank).iFrom).Allied += Infantry(intTank).Size
                                        Else
                                            Locat(Infantry(intTank).iFrom).Axis += Infantry(intTank).Size
                                        End If
                                    End If
                                Next
                            End If
                            .Unload = 1
                            .Direction = -1
                        End If
                    End If
                End If
            End With
        Next
    End Sub

    Public Sub LoadColOnShip(ByRef bolerror As Boolean, _
                            ByRef strerror As String, _
                            ByRef camsettings As Campaign, _
                            ByRef Col() As Column, _
                            ByRef Ship() As Column, _
                            ByRef Infantry() As Column, _
                            ByRef Locat() As Location, _
                            ByRef Harbor() As Location, _
                            ByRef RouteStart(,) As Integer, _
                            ByRef ColLoc() As String)
        Dim intShip As Integer
        Dim intTank As Integer
        Dim intRoom As Integer
        Dim iColLoc As Integer
        'This sub loads infantry and tanks onto a  ship
        If Ship.Length < 2 Then Exit Sub
        If Col.Length < 2 Then Exit Sub
        For intShip = 1 To Ship.Length - 1
            intRoom = 0
            With Ship(intShip)
                If .iFrom > 0 Then
                    If .Columns > 0 And _
                        Locat(Harbor(.iFrom).intRoad).Side = .Side And _
                        InStr(.sFrom, "_Harbor") > 0 Then
                        Select Case .Side
                            Case 1
                                If .iFrom <> RouteStart(2, 3) And _
                                        .sFrom <> camsettings.RuNavalStop Then
                                    intRoom = .Columns
                                    'Find Columns already loaded
                                    For intTank = 1 To Col.Length - 1
                                        If Col(intTank).sFrom = .Ident Then
                                            intRoom = intRoom - 1
                                            .Direction = 1
                                        End If
                                    Next
                                    'Find infantry already loaded
                                    If Infantry.Length > 1 Then
                                        For intTank = 1 To Infantry.Length - 1
                                            If Infantry(intTank).sFrom = .Ident Then
                                                intRoom = intRoom - 1
                                                .Direction = 1
                                            End If
                                        Next
                                    End If
                                    'load columns
                                    For intTank = 1 To Col.Length - 1
                                        If intRoom < 1 Then Exit For
                                        If Col(intTank).iFrom = Harbor(.iFrom).intRoad And _
                                            Col(intTank).AllowLoad > 0 Then
                                            If Col(intTank).Troops > 1 Then
                                                Locat(Col(intTank).iFrom).Allied = Locat(Col(intTank).iFrom).Allied - Col(intTank).Troops
                                            Else
                                                If InStr(Col(intTank).Unit, "Armor.") > 0 Or InStr(Col(intTank).Unit, "Infantry.") > 0 Then
                                                    Locat(Col(intTank).iFrom).Allied = Locat(Col(intTank).iFrom).Allied - (Col(intTank).Size * ptTank)
                                                Else
                                                    Locat(Col(intTank).iFrom).Allied = Locat(Col(intTank).iFrom).Allied - ptCar
                                                End If
                                            End If
                                            Col(intTank).sFrom = .Ident
                                            Col(intTank).sTo = .Ident
                                            Col(intTank).iFrom = -1
                                            Col(intTank).iFrom = -1
                                            intRoom = intRoom - 1
                                            .Direction = 1
                                            If ColLoc.Length > 1 Then
                                                For iColLoc = 1 To ColLoc.Length - 1
                                                    Dim sArray() As String
                                                    sArray = ColLoc(iColLoc).Split(" ")
                                                    If Col(intTank).Ident = sArray(0) Then
                                                        ColLoc(iColLoc) = Col(intTank).Ident & " @" & .Ident
                                                        Exit For
                                                    End If
                                                Next
                                            End If
                                        End If
                                    Next
                                    'load infantry
                                    If Infantry.Length > 1 Then
                                        For intTank = 1 To Infantry.Length - 1
                                            If intRoom < 1 Then Exit For
                                            If Infantry(intTank).iFrom = Harbor(.iFrom).intRoad And _
                                                Infantry(intTank).AllowLoad > 0 Then
                                                If Infantry(intTank).Troops > 1 Then
                                                    Locat(Infantry(intTank).iFrom).Allied = Locat(Infantry(intTank).iFrom).Allied - Infantry(intTank).Troops
                                                Else
                                                    If InStr(Infantry(intTank).Unit, "Armor.") > 0 Or InStr(Infantry(intTank).Unit, "Infantry.") > 0 Then
                                                        Locat(Infantry(intTank).iFrom).Allied = Locat(Infantry(intTank).iFrom).Allied - (Infantry(intTank).Size * ptTank)
                                                    Else
                                                        Locat(Infantry(intTank).iFrom).Allied = Locat(Infantry(intTank).iFrom).Allied - ptCar
                                                    End If
                                                End If
                                                Infantry(intTank).sFrom = .Ident
                                                Infantry(intTank).sTo = .Ident
                                                Infantry(intTank).iFrom = -1
                                                Infantry(intTank).iFrom = -1
                                                intRoom = intRoom - 1
                                                .Direction = 1
                                                If ColLoc.Length > 1 Then
                                                    For iColLoc = 1 To ColLoc.Length - 1
                                                        Dim sArray() As String
                                                        sArray = ColLoc(iColLoc).Split(" ")
                                                        If Infantry(intTank).Ident = sArray(0) Then
                                                            ColLoc(iColLoc) = Infantry(intTank).Ident & " @" & .Ident
                                                            Exit For
                                                        End If
                                                    Next
                                                End If
                                            End If
                                        Next
                                    End If
                                End If
                            Case 2
                                If .iFrom <> RouteStart(1, .Type) And _
                                        .sFrom <> camsettings.DeNavalStop Then
                                    intRoom = .Columns
                                    'Find columns already loaded
                                    For intTank = 1 To Col.Length - 1
                                        If Col(intTank).sFrom = .Ident Then
                                            intRoom = intRoom - 1
                                            .Direction = 1
                                        End If
                                    Next
                                    'Find infantry already loaded
                                    If Infantry.Length > 1 Then
                                        For intTank = 1 To Infantry.Length - 1
                                            If Infantry(intTank).sFrom = .Ident Then
                                                intRoom = intRoom - 1
                                                .Direction = 1
                                            End If
                                        Next
                                    End If
                                    'Load columns
                                    For intTank = 1 To Col.Length - 1
                                        If intRoom < 1 Then Exit For
                                        If Col(intTank).iFrom = Harbor(.iFrom).intRoad And _
                                            Col(intTank).AllowLoad > 0 Then
                                            If Col(intTank).Troops > 1 Then
                                                Locat(Col(intTank).iFrom).Axis = Locat(Col(intTank).iFrom).Axis - Col(intTank).Troops
                                            Else
                                                If InStr(Col(intTank).Unit, "Armor.") > 0 Or InStr(Col(intTank).Unit, "Infantry.") > 0 Then
                                                    Locat(Col(intTank).iFrom).Axis = Locat(Col(intTank).iFrom).Axis - (Col(intTank).Size * ptTank)
                                                Else
                                                    Locat(Col(intTank).iFrom).Axis = Locat(Col(intTank).iFrom).Axis - ptCar
                                                End If
                                            End If
                                            Col(intTank).sFrom = .Ident
                                            Col(intTank).sTo = .Ident
                                            Col(intTank).iFrom = -1
                                            Col(intTank).iFrom = -1
                                            intRoom = intRoom - 1
                                            .Direction = 1
                                            If ColLoc.Length > 1 Then
                                                For iColLoc = 1 To ColLoc.Length - 1
                                                    Dim sArray() As String
                                                    sArray = ColLoc(iColLoc).Split(" ")
                                                    If Col(intTank).Ident = sArray(0) Then
                                                        ColLoc(iColLoc) = Col(intTank).Ident & " @" & .Ident
                                                        Exit For
                                                    End If
                                                Next
                                            End If
                                        End If
                                    Next
                                    'Load Infantry
                                    If Infantry.Length > 1 Then
                                        For intTank = 1 To Infantry.Length - 1
                                            If intRoom < 1 Then Exit For
                                            If Infantry(intTank).iFrom = Harbor(.iFrom).intRoad And _
                                                Infantry(intTank).AllowLoad > 0 Then
                                                If Infantry(intTank).Troops > 1 Then
                                                    Locat(Infantry(intTank).iFrom).Axis = Locat(Infantry(intTank).iFrom).Axis - Infantry(intTank).Troops
                                                Else
                                                    If InStr(Infantry(intTank).Unit, "Armor.") > 0 Or InStr(Infantry(intTank).Unit, "Infantry.") > 0 Then
                                                        Locat(Infantry(intTank).iFrom).Axis = Locat(Infantry(intTank).iFrom).Axis - (Infantry(intTank).Size * ptTank)
                                                    Else
                                                        Locat(Infantry(intTank).iFrom).Axis = Locat(Infantry(intTank).iFrom).Axis - ptCar
                                                    End If
                                                End If
                                                Infantry(intTank).sFrom = .Ident
                                                Infantry(intTank).sTo = .Ident
                                                Infantry(intTank).iFrom = -1
                                                Infantry(intTank).iFrom = -1
                                                intRoom = intRoom - 1
                                                .Direction = 1
                                                If ColLoc.Length > 1 Then
                                                    For iColLoc = 1 To ColLoc.Length - 1
                                                        Dim sArray() As String
                                                        sArray = ColLoc(iColLoc).Split(" ")
                                                        If Infantry(intTank).Ident = sArray(0) Then
                                                            ColLoc(iColLoc) = Infantry(intTank).Ident & " @" & .Ident
                                                            Exit For
                                                        End If
                                                    Next
                                                End If
                                            End If
                                        Next
                                    End If
                                End If
                        End Select
                    End If

                End If
            End With
        Next
    End Sub

    Public Sub LoadColOnTrain(ByRef bolerror As Boolean, _
                                ByRef strerror As String, _
                                ByRef Col() As Column, _
                                ByRef Train() As Column, _
                                ByRef Infantry() As Column, _
                                ByRef Locat() As Location, _
                                ByRef Station() As Location, _
                                ByRef Rail() As Waypoint, _
                                ByRef ColLoc() As String)
        Dim intTrain As Integer
        Dim intTank As Integer
        Dim intRoom As Integer
        Dim bMove As Boolean
        Dim iTrainRoute As Integer
        Dim iColLoc As Integer
        'This sub loads infantry and columns onto a train
        If Train.Length < 2 Then Exit Sub
        If Col.Length < 2 Then Exit Sub
        For intTrain = 1 To Train.Length - 1
            With Train(intTrain)
                intRoom = .Columns
                If .iFrom > 0 And _
                    .Unload < 1 And _
                    .Direction > 0 And _
                    .Columns > 0 Then
                    'find columns already loaded
                    For intTank = 1 To Col.Length - 1
                        If Col(intTank).sFrom = .Ident Then intRoom = intRoom - 1
                    Next
                    'find infantry already loaded
                    If Infantry.Length > 1 Then
                        For intTank = 1 To Infantry.Length - 1
                            If Infantry(intTank).sFrom = .Ident Then intRoom = intRoom - 1
                        Next
                    End If
                    bMove = False
                    For iTrainRoute = 1 To Rail.Length - 1
                        If (.Side = 2 And .iFrom = Rail(iTrainRoute).iFrom) Or _
                            (.Side = 1 And .iFrom = Rail(iTrainRoute).iTo) Then
                            If .Side = 1 Then
                                If Station(Rail(iTrainRoute).iFrom).Side = .Side Then
                                    bMove = True
                                End If
                            Else
                                If Station(Rail(iTrainRoute).iTo).Side = .Side Then
                                    bMove = True
                                End If
                            End If
                        End If
                    Next
                    If bMove And intRoom > 0 Then
                        Select Case .Side
                            Case 1
                                'Load Columns
                                For intTank = 1 To Col.Length - 1
                                    If intRoom < 1 Then Exit For
                                    If Col(intTank).iFrom = Station(.iFrom).intRoad And _
                                            Col(intTank).AllowLoad > 0 Then
                                        If Col(intTank).Troops > 1 Then
                                            Locat(Col(intTank).iFrom).Allied = Locat(Col(intTank).iFrom).Allied - Col(intTank).Troops
                                        Else
                                            If InStr(Col(intTank).Unit, "Armor.") > 0 Or InStr(Col(intTank).Unit, "Infantry.") > 0 Then
                                                Locat(Col(intTank).iFrom).Allied = Locat(Col(intTank).iFrom).Allied - (Col(intTank).Size * ptTank)
                                            Else
                                                Locat(Col(intTank).iFrom).Allied = Locat(Col(intTank).iFrom).Allied - ptCar
                                            End If
                                        End If
                                        Col(intTank).sFrom = .Ident
                                        Col(intTank).sTo = .Ident
                                        Col(intTank).iFrom = -1
                                        Col(intTank).iFrom = -1
                                        intRoom = intRoom - 1
                                        If ColLoc.Length > 1 Then
                                            For iColLoc = 1 To ColLoc.Length - 1
                                                Dim sArray() As String
                                                sArray = ColLoc(iColLoc).Split(" ")
                                                If Col(intTank).Ident = sArray(0) Then
                                                    ColLoc(iColLoc) = Col(intTank).Ident & " @" & .Ident
                                                    Exit For
                                                End If
                                            Next
                                        End If
                                    End If
                                Next
                                'load infantry
                                If Infantry.Length > 1 Then
                                    For intTank = 1 To Infantry.Length - 1
                                        If intRoom < 1 Then Exit For
                                        If Infantry(intTank).iFrom = Station(.iFrom).intRoad And _
                                            Infantry(intTank).AllowLoad > 0 Then
                                            If Infantry(intTank).Troops > 1 Then
                                                Locat(Infantry(intTank).iFrom).Allied = Locat(Infantry(intTank).iFrom).Allied - Infantry(intTank).Troops
                                            Else
                                                If InStr(Infantry(intTank).Unit, "Armor.") > 0 Or InStr(Infantry(intTank).Unit, "Infantry.") > 0 Then
                                                    Locat(Infantry(intTank).iFrom).Allied = Locat(Infantry(intTank).iFrom).Allied - (Infantry(intTank).Size * ptTank)
                                                Else
                                                    Locat(Infantry(intTank).iFrom).Allied = Locat(Infantry(intTank).iFrom).Allied - ptCar
                                                End If
                                            End If
                                            Infantry(intTank).sFrom = .Ident
                                            Infantry(intTank).sTo = .Ident
                                            Infantry(intTank).iFrom = -1
                                            Infantry(intTank).iFrom = -1
                                            intRoom = intRoom - 1
                                            If ColLoc.Length > 1 Then
                                                For iColLoc = 1 To ColLoc.Length - 1
                                                    Dim sArray() As String
                                                    sArray = ColLoc(iColLoc).Split(" ")
                                                    If Infantry(intTank).Ident = sArray(0) Then
                                                        ColLoc(iColLoc) = Infantry(intTank).Ident & " @" & .Ident
                                                        Exit For
                                                    End If
                                                Next
                                            End If
                                        End If
                                    Next
                                End If
                            Case 2
                                'load columns
                                For intTank = 1 To Col.Length - 1
                                    If intRoom < 1 Then Exit For
                                    If Col(intTank).iFrom = Station(.iFrom).intRoad And _
                                            Col(intTank).AllowLoad > 0 Then
                                        If Col(intTank).Troops > 1 Then
                                            Locat(Col(intTank).iFrom).Axis = Locat(Col(intTank).iFrom).Axis - Col(intTank).Troops
                                        Else
                                            If InStr(Col(intTank).Unit, "Armor.") > 0 Or InStr(Col(intTank).Unit, "Infantry.") > 0 Then
                                                Locat(Col(intTank).iFrom).Axis = Locat(Col(intTank).iFrom).Axis - (Col(intTank).Size * ptTank)
                                            Else
                                                Locat(Col(intTank).iFrom).Axis = Locat(Col(intTank).iFrom).Axis - ptCar
                                            End If
                                        End If
                                        Col(intTank).sFrom = .Ident
                                        Col(intTank).sTo = .Ident
                                        Col(intTank).iFrom = -1
                                        Col(intTank).iFrom = -1
                                        intRoom = intRoom - 1
                                        If ColLoc.Length > 1 Then
                                            For iColLoc = 1 To ColLoc.Length - 1
                                                Dim sArray() As String
                                                sArray = ColLoc(iColLoc).Split(" ")
                                                If Col(intTank).Ident = sArray(0) Then
                                                    ColLoc(iColLoc) = Col(intTank).Ident & " @" & .Ident
                                                    Exit For
                                                End If
                                            Next
                                        End If
                                    End If
                                Next
                                'load infantry
                                If Infantry.Length > 1 Then
                                    For intTank = 1 To Infantry.Length - 1
                                        If intRoom < 1 Then Exit For
                                        If Infantry(intTank).iFrom = Station(.iFrom).intRoad And _
                                            Infantry(intTank).AllowLoad > 0 Then
                                            If Infantry(intTank).Troops > 1 Then
                                                Locat(Infantry(intTank).iFrom).Axis = Locat(Infantry(intTank).iFrom).Axis - Infantry(intTank).Troops
                                            Else
                                                If InStr(Infantry(intTank).Unit, "Armor.") > 0 Or InStr(Infantry(intTank).Unit, "Infantry.") > 0 Then
                                                    Locat(Infantry(intTank).iFrom).Axis = Locat(Infantry(intTank).iFrom).Axis - (Infantry(intTank).Size * ptTank)
                                                Else
                                                    Locat(Infantry(intTank).iFrom).Axis = Locat(Infantry(intTank).iFrom).Axis - ptCar
                                                End If
                                            End If
                                            Infantry(intTank).sFrom = .Ident
                                            Infantry(intTank).sTo = .Ident
                                            Infantry(intTank).iFrom = -1
                                            Infantry(intTank).iFrom = -1
                                            intRoom = intRoom - 1
                                            If ColLoc.Length > 1 Then
                                                For iColLoc = 1 To ColLoc.Length - 1
                                                    Dim sArray() As String
                                                    sArray = ColLoc(iColLoc).Split(" ")
                                                    If Infantry(intTank).Ident = sArray(0) Then
                                                        ColLoc(iColLoc) = Infantry(intTank).Ident & " @" & .Ident
                                                        Exit For
                                                    End If
                                                Next
                                            End If
                                        End If
                                    Next
                                End If
                        End Select
                    End If
                End If
            End With
        Next
    End Sub

    Public Sub UpdateShips(ByRef bolerror As Boolean, _
                            ByRef strerror As String, _
                            ByRef ColLoc() As String, _
                            ByRef camsettings As Campaign, _
                            ByRef Ship() As Column, _
                            ByRef Harbor() As Location, _
                            ByRef ShipRoute() As Waypoint, _
                            ByRef strDebrief() As String, _
                            ByRef RouteStart(,) As Integer, _
                            ByRef INI_Settings As INI_Class)
        Dim intShip As Integer
        Dim intHarb As Integer
        Dim sngRnd As Single
        Dim intPosTo As Integer
        Dim PosTo(0) As Waypoint
        'This sub decides if a Ship will move to the next harbor
        If Ship.Length < 2 Then Exit Sub

        For intShip = 1 To Ship.Length - 1
            Select Case Ship(intShip).sFrom

                Case Is = "Blank"
                    sngRnd = Rnd()
                    If sngRnd < INI_Settings.ShipSpawn Then
                        With Ship(intShip)
                            If Harbor(RouteStart(.Side, 3)).Side = .Side Then
                                .sFrom = Harbor(RouteStart(.Side, 3)).Loc
                                .sTo = Harbor(RouteStart(.Side, 3)).Loc
                                .iFrom = RouteStart(.Side, 3)
                                .iTo = RouteStart(.Side, 3)
                                .Direction = 1
                            End If
                        End With

                    End If
                Case Else

                    'Move Ship

                    If Ship(intShip).iFrom > 0 Then  'At a Harbor

                        If Ship(intShip).Side = Harbor(Ship(intShip).iFrom).Side Then
                            intPosTo = 0
                            If Not Ship(intShip).Hold Then
                                'Add Ships location to the ColLoc file
                                ReDim Preserve ColLoc(ColLoc.Length)
                                ColLoc(ColLoc.Length - 1) = Ship(intShip).Ident & " @" & Ship(intShip).sFrom
                                For intHarb = 1 To ShipRoute.Length - 1
                                    If ShipRoute(intHarb).iTo = Ship(intShip).iTo Then
                                        If Harbor(ShipRoute(intHarb).iFrom).Side = Ship(intShip).Side Then
                                            ColLoc(ColLoc.Length - 1) = ColLoc(ColLoc.Length - 1) & " @" & ShipRoute(intHarb).strFrom
                                        End If
                                    End If
                                    If ShipRoute(intHarb).iFrom = Ship(intShip).iTo Then
                                        If Harbor(ShipRoute(intHarb).iTo).Side = Ship(intShip).Side Then
                                            ColLoc(ColLoc.Length - 1) = ColLoc(ColLoc.Length - 1) & " @" & ShipRoute(intHarb).strTo
                                        End If
                                    End If
                                Next
                                Select Case Ship(intShip).Side
                                    Case 1
                                        If Ship(intShip).sFrom <> camsettings.RuNavalStop Or _
                                            Ship(intShip).Columns > 0 Then
                                            For intHarb = 1 To ShipRoute.Length - 1
                                                If ShipRoute(intHarb).iTo = Ship(intShip).iFrom And _
                                                    Ship(intShip).Direction > 0 Then
                                                    intPosTo = intPosTo + 1
                                                    ReDim Preserve PosTo(intPosTo)
                                                    PosTo(intPosTo).iTo = ShipRoute(intHarb).iFrom
                                                    PosTo(intPosTo).strTo = ShipRoute(intHarb).strFrom
                                                End If
                                                If ShipRoute(intHarb).iFrom = Ship(intShip).iFrom And _
                                                    Ship(intShip).Direction < 0 Then
                                                    intPosTo = intPosTo + 1
                                                    ReDim Preserve PosTo(intPosTo)
                                                    PosTo(intPosTo).iTo = ShipRoute(intHarb).iTo
                                                    PosTo(intPosTo).strTo = ShipRoute(intHarb).strTo
                                                End If
                                            Next
                                        End If

                                    Case 2
                                        If Ship(intShip).sFrom <> camsettings.DeNavalStop Or _
                                            Ship(intShip).Columns > 0 Then
                                            For intHarb = 1 To ShipRoute.Length - 1
                                                If ShipRoute(intHarb).iFrom = Ship(intShip).iFrom And _
                                                    Ship(intShip).Direction > 0 Then
                                                    intPosTo = intPosTo + 1
                                                    ReDim Preserve PosTo(intPosTo)
                                                    PosTo(intPosTo).iTo = ShipRoute(intHarb).iTo
                                                    PosTo(intPosTo).strTo = ShipRoute(intHarb).strTo
                                                End If
                                                If ShipRoute(intHarb).iTo = Ship(intShip).iFrom And _
                                                    Ship(intShip).Direction < 0 Then
                                                    intPosTo = intPosTo + 1
                                                    ReDim Preserve PosTo(intPosTo)
                                                    PosTo(intPosTo).iTo = ShipRoute(intHarb).iFrom
                                                    PosTo(intPosTo).strTo = ShipRoute(intHarb).strFrom
                                                End If
                                            Next
                                        End If
                                End Select
                            End If
                            If intPosTo > 0 Then
                                sngRnd = Rnd() * intPosTo
                                intHarb = Int(sngRnd + 1)
                                intHarb = PosTo(intHarb).iTo
                                Ship(intShip).iTo = intHarb
                                Ship(intShip).sTo = Harbor(intHarb).Loc
                            Else
                                With Ship(intShip)
                                    Select Case .Side
                                        Case 1
                                            If (.iFrom = RouteStart(2, 3)) Or _
                                                    (.iFrom = RouteStart(1, 3)) Then
                                                If .iFrom = RouteStart(1, 3) Then .Direction = 1
                                                If .iFrom = RouteStart(2, 3) Then .Direction = -1
                                            Else
                                                If Not .Hold Then

                                                    ReDim Preserve strDebrief(strDebrief.Length)
                                                    strDebrief(strDebrief.Length - 1) = "Possible error in ship system" & Ship(intShip).Ident & " " & Ship(intShip).sFrom
                                                End If
                                            End If

                                        Case 2
                                            If (.iFrom = RouteStart(2, 3)) Or _
                                                    (.iFrom = RouteStart(1, 3)) Then
                                                If .iFrom = RouteStart(2, 3) Then .Direction = 1
                                                If .iFrom = RouteStart(1, 3) Then .Direction = -1
                                            Else
                                                If Not .Hold Then

                                                    ReDim Preserve strDebrief(strDebrief.Length)
                                                    strDebrief(strDebrief.Length - 1) = "Possible error in ship system" & Ship(intShip).Ident & " " & Ship(intShip).sFrom
                                                End If
                                            End If
                                            If .iFrom <> RouteStart(2, 3) Then .Direction = 1
                                    End Select
                                End With
                            End If
                        End If
                    End If
            End Select
        Next
    End Sub
    Public Sub UpdateTrains(ByRef bolerror As Boolean, _
                            ByRef strerror As String, _
                            ByRef ColLoc() As String, _
                            ByRef Bridge() As Brid, _
                            ByRef MissSettings As Mission, _
                            ByRef Train() As Column, _
                            ByRef Station() As Location, _
                            ByRef Rail() As Waypoint, _
                            ByRef strDebrief() As String, _
                            ByRef RouteStart(,) As Integer, _
                            ByRef INI_Settings As INI_Class)
        Dim intTrain As Integer
        Dim intStat As Integer
        Dim sngRnd As Single
        Dim intPosTo As Integer
        Dim PosTo(0) As Waypoint
        Dim intCntBdg As Integer
        'This sub decides if a Train will move to the next Station
        If Train.Length < 2 Then Exit Sub
        For intTrain = 1 To Train.Length - 1
            Select Case Train(intTrain).sFrom
                Case Is = "Blank"
                    sngRnd = Rnd()
                    If sngRnd < INI_Settings.TrainSpawn Then
                        With Train(intTrain)
                            If Station(RouteStart(.Side, 2)).Side = .Side Then
                                .sFrom = Station(RouteStart(.Side, 2)).Loc
                                .sTo = Station(RouteStart(.Side, 2)).Loc
                                .iFrom = RouteStart(.Side, 2)
                                .iTo = RouteStart(.Side, 2)
                                .Direction = 1
                            End If
                        End With
                    End If
                Case Else
                    'Move Train
                    If Train(intTrain).iFrom > 0 Then
                        If Train(intTrain).Side = Station(Train(intTrain).iFrom).Side Or _
                            Train(intTrain).Direction < 0 Then
                            intPosTo = 0
                            If Not Train(intTrain).Hold Then
                                'Add Trains location to the ColLoc file
                                ReDim Preserve ColLoc(ColLoc.Length)
                                ColLoc(ColLoc.Length - 1) = Train(intTrain).Ident & " @" & Train(intTrain).sFrom
                                For intStat = 1 To Rail.Length - 1
                                    If Train(intTrain).iTo = Rail(intStat).iTo Then
                                        If Station(Rail(intStat).iFrom).Side = Train(intTrain).Side Then
                                            ColLoc(ColLoc.Length - 1) = ColLoc(ColLoc.Length - 1) & " @" & Rail(intStat).strFrom
                                        End If
                                    End If
                                    If Train(intTrain).iTo = Rail(intStat).iFrom Then
                                        If Station(Rail(intStat).iTo).Side = Train(intTrain).Side Then
                                            ColLoc(ColLoc.Length - 1) = ColLoc(ColLoc.Length - 1) & " @" & Rail(intStat).strTo
                                        End If
                                    End If
                                Next
                                Select Case Train(intTrain).Side
                                    Case 1
                                        For intStat = 1 To Rail.Length - 1
                                            If Rail(intStat).iTo = Train(intTrain).iFrom And _
                                                Station(Rail(intStat).iFrom).Side = Train(intTrain).Side And _
                                                Train(intTrain).Direction > 0 Then
                                                If Bridge.Length > 1 And MissSettings.Bridge > 1 Then
                                                    For intCntBdg = Bridge.Length - 1 To 1 Step -1
                                                        If Rail(intStat).strTo = Bridge(intCntBdg).sTo And _
                                                            Rail(intStat).strFrom = Bridge(intCntBdg).sFrom Then
                                                            Exit For
                                                        End If
                                                    Next
                                                Else
                                                    intCntBdg = 0
                                                End If
                                                If intCntBdg < 1 Then
                                                    intPosTo = intPosTo + 1
                                                    ReDim Preserve PosTo(intPosTo)
                                                    PosTo(intPosTo).iTo = Rail(intStat).iFrom
                                                    PosTo(intPosTo).strTo = Rail(intStat).strFrom
                                                End If
                                            End If
                                            If Rail(intStat).iFrom = Train(intTrain).iFrom And _
                                                Station(Rail(intStat).iTo).Side = Train(intTrain).Side And _
                                                Train(intTrain).Direction < 0 Then
                                                If Bridge.Length > 1 And MissSettings.Bridge > 1 Then
                                                    For intCntBdg = Bridge.Length - 1 To 1 Step -1
                                                        If Rail(intStat).strTo = Bridge(intCntBdg).sTo And _
                                                            Rail(intStat).strFrom = Bridge(intCntBdg).sFrom Then
                                                            Exit For
                                                        End If
                                                    Next
                                                Else
                                                    intCntBdg = 0
                                                End If
                                                If intCntBdg < 1 Then
                                                    intPosTo = intPosTo + 1
                                                    ReDim Preserve PosTo(intPosTo)
                                                    PosTo(intPosTo).iTo = Rail(intStat).iTo
                                                    PosTo(intPosTo).strTo = Rail(intStat).strTo
                                                End If

                                            End If
                                        Next
                                    Case 2
                                        For intStat = 1 To Rail.Length - 1
                                            If Rail(intStat).iFrom = Train(intTrain).iFrom And _
                                            Station(Rail(intStat).iTo).Side = Train(intTrain).Side And _
                                                Train(intTrain).Direction > 0 Then

                                                If Bridge.Length > 1 And MissSettings.Bridge > 1 Then
                                                    For intCntBdg = Bridge.Length - 1 To 1 Step -1
                                                        If Rail(intStat).strTo = Bridge(intCntBdg).sTo And _
                                                            Rail(intStat).strFrom = Bridge(intCntBdg).sFrom Then
                                                            Exit For
                                                        End If
                                                    Next
                                                Else
                                                    intCntBdg = 0
                                                End If
                                                If intCntBdg < 1 Then
                                                    intPosTo = intPosTo + 1
                                                    ReDim Preserve PosTo(intPosTo)
                                                    PosTo(intPosTo).iTo = Rail(intStat).iTo
                                                    PosTo(intPosTo).strTo = Rail(intStat).strTo
                                                End If
                                            End If
                                            If Rail(intStat).iTo = Train(intTrain).iFrom And _
                                        Station(Rail(intStat).iFrom).Side = Train(intTrain).Side And _
                                        Train(intTrain).Direction < 0 Then
                                                If Bridge.Length > 1 And MissSettings.Bridge > 1 Then
                                                    For intCntBdg = Bridge.Length - 1 To 1 Step -1
                                                        If Rail(intStat).strTo = Bridge(intCntBdg).sTo And _
                                                            Rail(intStat).strFrom = Bridge(intCntBdg).sFrom Then
                                                            Exit For
                                                        End If
                                                    Next
                                                Else
                                                    intCntBdg = 0
                                                End If
                                                If intCntBdg < 1 Then
                                                    intPosTo = intPosTo + 1
                                                    ReDim Preserve PosTo(intPosTo)
                                                    PosTo(intPosTo).iTo = Rail(intStat).iFrom
                                                    PosTo(intPosTo).strTo = Rail(intStat).strFrom
                                                End If
                                            End If
                                        Next
                                End Select
                            End If
                            If intPosTo > 0 Then
                                sngRnd = Rnd() * intPosTo
                                intStat = Int(sngRnd + 1)
                                intStat = PosTo(intStat).iTo
                                If Station(intStat).Side = Train(intTrain).Side Then
                                    Train(intTrain).iTo = intStat
                                    Train(intTrain).sTo = Station(intStat).Loc
                                Else
                                    Train(intTrain).iTo = Train(intTrain).iFrom
                                    Train(intTrain).sTo = Train(intTrain).sFrom
                                End If
                            Else
                                With Train(intTrain)
                                    Select Case .Side
                                        Case 1
                                            If .iFrom = RouteStart(2, 2) Or _
                                                    .iFrom = RouteStart(1, 2) Then
                                                If .iFrom = RouteStart(2, 2) Then .Direction = -1
                                                If .iFrom = RouteStart(1, 2) Then .Direction = 1
                                            Else
                                                If Not .Hold Then

                                                    ReDim Preserve strDebrief(strDebrief.Length)
                                                    strDebrief(strDebrief.Length - 1) = "Possible error in rail system or bridge may be down " & Train(intTrain).Ident & " " & Train(intTrain).sFrom
                                                End If
                                            End If
                                        Case 2
                                            If .iFrom = RouteStart(2, 2) Or _
                                                    .iFrom = RouteStart(1, 2) Then
                                                If .iFrom = RouteStart(2, 2) Then .Direction = 1
                                                If .iFrom = RouteStart(1, 2) Then .Direction = -1
                                            Else
                                                If Not .Hold Then

                                                    ReDim Preserve strDebrief(strDebrief.Length)
                                                    strDebrief(strDebrief.Length - 1) = "Possible error in rail system or bridge may be down " & Train(intTrain).Ident & " " & Train(intTrain).sFrom
                                                End If
                                            End If
                                    End Select
                                End With
                            End If
                        End If
                    End If
            End Select
        Next
    End Sub


    Public Sub FixDestroyed(ByRef bolerror As Boolean, _
                            ByRef strerror As String, _
                            ByRef Col() As Column, _
                            ByRef Ship() As Column, _
                            ByRef Train() As Column, _
                            ByRef Infantry() As Column)
        Dim intCount As Integer
        'this sub changes columns/trains/ships from destroyed to blank
        If Col.Length > 1 Then
            For intCount = 1 To Col.Length - 1
                With Col(intCount)
                    If .sFrom = "Destroyed" Then
                        .sFrom = "Blank"
                        .sTo = "Blank"
                        .iFrom = -1
                        .iTo = -1
                        .Size = .OrigSize
                        .Curr = .OrigSize
                    End If
                End With
            Next
        End If
        If Train.Length > 1 Then
            For intCount = 1 To Train.Length - 1
                With Train(intCount)
                    If .sFrom = "Destroyed" Then
                        .sFrom = "Blank"
                        .sTo = "Blank"
                        .iFrom = 0
                        .iTo = 0
                        .Size = .OrigSize
                        .Curr = .OrigSize
                    End If
                End With
            Next
        End If
        If Ship.Length > 1 Then
            For intCount = 1 To Ship.Length - 1
                With Ship(intCount)
                    If .sFrom = "Destroyed" Then
                        .sFrom = "Blank"
                        .sTo = "Blank"
                        .iFrom = 0
                        .iTo = 0
                        .Size = .OrigSize
                        .Curr = .OrigSize
                    End If
                End With
            Next
        End If
        If infantry.Length > 1 Then
            For intCount = 1 To Infantry.Length - 1
                With Infantry(intCount)
                    If .sFrom = "Destroyed" Then
                        .sFrom = "Blank"
                        .sTo = "Blank"
                        .iFrom = 0
                        .iTo = 0
                        .Size = .OrigSize
                        .Curr = .OrigSize
                    End If
                End With
            Next
        End If
    End Sub
    Public Sub Manufacture_Units(ByRef bolerror As Boolean, _
                            ByRef strerror As String, _
                            ByRef Fact() As Factory, _
                            ByRef Col() As Column, _
                            ByRef Locat() As Location, _
                            ByRef INI_Settings As INI_Class, _
                            ByRef Infantry() As Column, _
                            ByRef Manufacture() As Factory, _
                            ByRef ColLoc() As String)
        Dim intFact As Integer
        Dim intCol As Integer
        Dim sngRnd As Single
        Dim intUp As Integer
        Dim iLoc As Integer
        Dim iSpawn As Integer
        'This sub spawns columns at factories and factory plates
        If Col.Length < 2 Then Exit Sub
        If Fact.Length > 1 Then
            For intFact = 1 To Fact.Length - 1
                sngRnd = Rnd()
                If sngRnd < INI_Settings.FactorySpawn Then
                    With Fact(intFact)
                        If .Active And .Col > 0 And Locat(.intLoc).Side > 0 Then
                            intUp = Int(Rnd() * 2)
                            If intUp > 0 Then
                                For intCol = 1 To Col.Length - 1
                                    If .Side = Col(intCol).Side And Col(intCol).sFrom = "Blank" Then
                                        Col(intCol).sFrom = .Loc
                                        Col(intCol).sTo = .Loc
                                        Col(intCol).iFrom = .intLoc
                                        Col(intCol).iTo = .intLoc
                                        Fix_ColLoc(ColLoc, _
                                                   .Loc, _
                                                   Col(intCol).Ident)
                                        If .Side = 1 Then
                                            If Col(intCol).Troops > 1 Then
                                                Locat(.intLoc).Allied = Locat(.intLoc).Allied + Col(intCol).Troops
                                            Else
                                                If InStr(Col(intCol).Unit, "Armor.") > 0 Or InStr(Col(intCol).Unit, "Infantry.") > 0 Then
                                                    Locat(.intLoc).Allied = Locat(.intLoc).Allied + (Col(intCol).Size * ptTank)
                                                Else
                                                    Locat(.intLoc).Allied = Locat(.intLoc).Allied + ptCar
                                                End If
                                            End If
                                        Else
                                            If Col(intCol).Troops > 1 Then
                                                Locat(.intLoc).Axis = Locat(.intLoc).Axis + Col(intCol).Troops
                                            Else
                                                If InStr(Col(intCol).Unit, "Armor.") > 0 Or InStr(Col(intCol).Unit, "Infantry.") > 0 Then
                                                    Locat(.intLoc).Axis = Locat(.intLoc).Axis + (Col(intCol).Size * ptTank)
                                                Else
                                                    Locat(.intLoc).Axis = Locat(.intLoc).Axis + ptCar
                                                End If
                                            End If
                                        End If
                                        Exit For
                                    End If
                                Next
                                'if no columns spawned try an infantry column
                                If intCol < 1 And infantry.Length > 1 Then
                                    For intCol = 1 To infantry.Length - 1
                                        If .Side = infantry(intCol).Side And infantry(intCol).sFrom = "Blank" Then
                                            infantry(intCol).sFrom = .Loc
                                            infantry(intCol).sTo = .Loc
                                            infantry(intCol).iFrom = .intLoc
                                            infantry(intCol).iTo = .intLoc
                                            Fix_ColLoc(ColLoc, _
                                                   .Loc, _
                                                   Infantry(intCol).Ident)
                                            If .Side = 1 Then
                                                Locat(.intLoc).Allied += infantry(intCol).Size
                                            Else
                                                Locat(.intLoc).Axis += infantry(intCol).Size
                                            End If
                                            Exit For
                                        End If
                                    Next
                                End If
                            Else
                                'Try infantry column first
                                If infantry.Length > 1 Then
                                    For intCol = 1 To infantry.Length - 1
                                        If .Side = infantry(intCol).Side And infantry(intCol).sFrom = "Blank" Then
                                            infantry(intCol).sFrom = .Loc
                                            infantry(intCol).sTo = .Loc
                                            infantry(intCol).iFrom = .intLoc
                                            Infantry(intCol).iTo = .intLoc
                                            Fix_ColLoc(ColLoc, _
                                                   .Loc, _
                                                   Infantry(intCol).Ident)
                                            If .Side = 1 Then
                                                Locat(.intLoc).Allied += infantry(intCol).Size
                                            Else
                                                Locat(.intLoc).Axis += infantry(intCol).Size
                                            End If
                                            Exit For
                                        End If
                                    Next
                                End If
                                If intCol < 1 And Col.Length > 1 Then
                                    For intCol = Col.Length - 1 To 1 Step -1
                                        If .Side = Col(intCol).Side And Col(intCol).sFrom = "Blank" Then
                                            Col(intCol).sFrom = .Loc
                                            Col(intCol).sTo = .Loc
                                            Col(intCol).iFrom = .intLoc
                                            Col(intCol).iTo = .intLoc
                                            Fix_ColLoc(ColLoc, _
                                                   .Loc, _
                                                   Col(intCol).Ident)
                                            If .Side = 1 Then
                                                If Col(intCol).Troops > 1 Then
                                                    Locat(.intLoc).Allied = Locat(.intLoc).Allied + Col(intCol).Troops
                                                Else

                                                    If InStr(Col(intCol).Unit, "Armor.") > 0 Or InStr(Col(intCol).Unit, "Infantry.") > 0 Then
                                                        Locat(.intLoc).Allied = Locat(.intLoc).Allied + (Col(intCol).Size * ptTank)
                                                    Else
                                                        Locat(.intLoc).Allied = Locat(.intLoc).Allied + ptCar
                                                    End If
                                                End If
                                            Else
                                                If Col(intCol).Troops > 1 Then
                                                    Locat(.intLoc).Axis = Locat(.intLoc).Axis + Col(intCol).Troops
                                                Else
                                                    If InStr(Col(intCol).Unit, "Armor.") > 0 Or InStr(Col(intCol).Unit, "Infantry.") > 0 Then
                                                        Locat(.intLoc).Axis = Locat(.intLoc).Axis + (Col(intCol).Size * ptTank)
                                                    Else
                                                        Locat(.intLoc).Axis = Locat(.intLoc).Axis + ptCar
                                                    End If
                                                End If
                                            End If
                                            Exit For
                                        End If
                                    Next
                                End If
                            End If
                        End If
                    End With
                End If
            Next
        End If
        'Spawn units at factory plates
        If Manufacture.Length > 1 Then
            For iLoc = 1 To Locat.Length - 1
                Locat(iLoc).Manufacture = 0
            Next
            For intFact = 1 To Manufacture.Length - 1
                Locat(Manufacture(intFact).intLoc).Manufacture += Manufacture(intFact).Manufacture
            Next
            For iLoc = 1 To Locat.Length - 1
                With Locat(iLoc)
                    If .Side > 0 And .Manufacture > 0 Then
                        iSpawn = Math.Round(.Manufacture)
                        Dim iTotSpawn As Integer
                        Do While iSpawn > 0
                            iTotSpawn = iSpawn
                            If Col.Length > 1 Then
                                For intCol = 1 To Col.Length - 1
                                    If Col(intCol).sFrom = "Blank" And Col(intCol).Side = .Side Then
                                        Col(intCol).sFrom = .Loc
                                        Col(intCol).sTo = .Loc
                                        Col(intCol).iTo = iLoc
                                        Col(intCol).iFrom = iLoc
                                        Fix_ColLoc(ColLoc, _
                                                   .Loc, _
                                                   Col(intCol).Ident)
                                        iSpawn -= 1
                                        Exit For
                                    End If
                                Next
                            End If
                            If iSpawn < 1 Then Exit Do
                            If infantry.Length > 1 Then
                                For intCol = 1 To infantry.Length - 1
                                    If infantry(intCol).sFrom = "Blank" And infantry(intCol).Side = .Side Then
                                        infantry(intCol).sFrom = .Loc
                                        infantry(intCol).sTo = .Loc
                                        infantry(intCol).iTo = iLoc
                                        Infantry(intCol).iFrom = iLoc
                                        Fix_ColLoc(ColLoc, _
                                                   .Loc, _
                                                   Infantry(intCol).Ident)
                                        iSpawn -= 1
                                        Exit For
                                    End If
                                Next
                            End If
                            If iSpawn = iTotSpawn Then Exit Do
                        Loop
                    End If
                End With
            Next
        End If
    End Sub
    Public Sub RepairFactories(ByRef bolerror As Boolean, _
                            ByRef strerror As String, _
                            ByRef Fact() As Factory, _
                            ByRef MissSettings As Mission, _
                            ByRef Locat() As Location, _
                            ByRef strDebrief() As String, _
                            ByRef Manufacture() As Factory)
        Dim intFact As Integer
        Dim strOutput As String = ""
        Dim snRepair As Single
        'This sub repairs factories and factory plates
        If Locat.Length < 2 Then Exit Sub
        'Repair Factory building
        If Fact.Length > 1 Then
            For intFact = 1 To Fact.Length - 1
                With Fact(intFact)
                    If (Not .Active) And .Col > 0 And .Repair > 0 And Locat(.intLoc).Side > 0 Then
                        If MissSettings.FactRepair > 0 Then
                            snRepair = Rnd()
                            If snRepair < MissSettings.FactRepair Then
                                .Active = True
                                FindGrid(Locat(.intLoc).X, Locat(.intLoc).Y, strOutput)

                                ReDim Preserve strDebrief(strDebrief.Length)
                                strDebrief(strDebrief.Length - 1) = "Factory repaired at " & .Loc & " " & strOutput
                            End If
                        Else
                            If Locat(.intLoc).Supply >= .Repair Then
                                .Active = True
                                Locat(.intLoc).Supply -= .Repair
                                FindGrid(Locat(.intLoc).X, Locat(.intLoc).Y, strOutput)

                                ReDim Preserve strDebrief(strDebrief.Length)
                                strDebrief(strDebrief.Length - 1) = "Factory rebuilt from supplies at " & .Loc & " " & strOutput
                            End If
                        End If
                    End If
                End With
            Next
        End If
        'Repairs Factory Plates
        If Manufacture.Length > 1 Then
            For intFact = 1 To Manufacture.Length - 1
                With Manufacture(intFact)
                    .Side = Locat(.intLoc).Side
                    If .Side > 0 Then
                        .Manufacture += MissSettings.FactRepair * .MaxMan
                        If .Manufacture > .MaxMan Then .Manufacture = .MaxMan
                    End If
                End With
            Next
        End If
    End Sub
    Public Sub ShowSupply(ByRef bolerror As Boolean, _
                            ByRef strerror As String, _
                            ByRef Fact() As Factory, _
                            ByRef Locat() As Location)
        Dim intFact As Integer
        Dim intLoc As Integer
        Dim intFuel As Integer
        Dim intSupply As Integer
        'This sub shows Supply
        If Fact.Length < 2 Then Exit Sub
        If Locat.Length < 2 Then Exit Sub
        'set all fuel and Supply inactive
        For intFact = 1 To Fact.Length - 1
            With Fact(intFact)
                If .Supply > 0 Or .Fuel > 0 Then
                    .Active = False
                End If
            End With
        Next
        For intLoc = 1 To Locat.Length - 1
            With Locat(intLoc)
                If .Supply > .MaxSup Then .Supply = .MaxSup
                If .Fuel > .MaxFuel Then .Fuel = .MaxFuel
                intFuel = .Fuel
                intSupply = .Supply
                For intFact = 1 To Fact.Length - 1
                    If intFuel < 1 And intSupply < 1 Then Exit For
                    If intLoc = Fact(intFact).intLoc Then
                        If Fact(intFact).Fuel > 0 Then
                            If intFuel >= Fact(intFact).Fuel / 2 Then
                                intFuel = intFuel - Fact(intFact).Fuel
                                If intFuel < 0 Then intFuel = 0
                                Fact(intFact).Active = True
                            End If
                        End If
                        If Fact(intFact).Supply > 0 Then
                            If intSupply >= Fact(intFact).Supply / 2 Then
                                intSupply = intSupply - Fact(intFact).Supply
                                If intSupply < 0 Then intSupply = 0
                                Fact(intFact).Active = True
                            End If
                        End If
                    End If
                Next
            End With
        Next
    End Sub

    Public Sub LoadHouseFile(ByRef bolerror As Boolean, _
                            ByRef strerror As String, _
                            ByRef House() As String, _
                            ByRef INI_Settings As INI_Class)
        Dim strHouseFile As String
        Dim strInput As String
        Dim filereader As IO.StreamReader
        strHouseFile = INI_Settings.sCampaign & "\house.dcg"
        If Dir(strHouseFile) = "" Then Exit Sub
        If My.Computer.FileSystem.FileExists(strHouseFile) Then
            filereader = My.Computer.FileSystem.OpenTextFileReader(strHouseFile)
            Do Until filereader.EndOfStream
                strInput = filereader.ReadLine
                If strInput <> "" And InStr(strInput, "[House]") < 1 Then
                    ReDim Preserve House(House.Length)
                    House(House.Length - 1) = Trim(strInput)
                End If
            Loop
            filereader.Close()
        End If
    End Sub



    Public Sub GenMissFiles(ByRef bolerror As Boolean, _
                            ByRef strerror As String, _
                            ByRef Misweather As Integer, _
                            ByRef Miscloud As Integer, _
                            ByRef sMissFolder As String, _
                            ByRef Transport() As Carry, _
                            ByRef Wind As Weather, _
                            ByRef House() As String, _
                            ByRef BornPlace() As BornPlaceClass, _
                            ByRef ConvoyVeh(,) As String, _
                            ByRef ConvoyInfo() As Convoy, _
                            ByRef StructInfo() As Building, _
                            ByRef StructList(,) As String, _
                            ByRef Fact() As Factory, _
                            ByRef Rocket() As RocketType, _
                            ByRef camsettings As Campaign, _
                            ByRef MissSettings As Mission, _
                            ByRef Stat() As Stationary, _
                            ByRef Col() As Column, _
                            ByRef Ship() As Column, _
                            ByRef Train() As Column, _
                            ByRef Infantry() As Column, _
                            ByRef Locat() As Location, _
                            ByRef Station() As Location, _
                            ByRef Harbor() As Location, _
                            ByRef Road() As Waypoint, _
                            ByRef ShipRoute() As Waypoint, _
                            ByRef Rail() As Waypoint, _
                            ByRef Trail() As Waypoint, _
                            ByRef Bldg() As Stationary, _
                            ByRef strDebrief() As String, _
                            ByRef strFrontLine() As String, _
                            ByRef strACMove() As String, _
                            ByRef strBdgDown() As String, _
                            ByRef Chief() As String, _
                            ByRef ChiefMov() As String, _
                            ByRef ChiefRd() As String, _
                            ByRef DeadBridge() As String, _
                            ByRef RoadWp() As String, _
                            ByRef RailWP() As String, _
                            ByRef SeaWP() As WP, _
                            ByRef TrailWP() As String, _
                            ByRef Squad() As Squad_Type, _
                            ByRef UseSquad As Integer, _
                            ByRef Weapon() As Weap, _
                            ByRef MDS() As String, _
                            ByRef MODS() As String, _
                            ByRef SupplyAC() As AC_Supply, _
                            ByRef Radar() As Factory, _
                            ByRef RedCountry() As String, _
                            ByRef BlueCountry() As String, _
                            ByRef INI_Settings As INI_Class, _
                            ByRef MisTime As Single, _
                            ByRef Manufacture() As Factory)
        LoadDebriefs(strDebrief, _
                     strFrontLine, _
                     strACMove, _
                     strBdgDown, _
                     INI_Settings)
        Find_Transports(Transport, _
                        Col)
        'GndAircraft(bolerror, _
        '            strerror, _
        '            Stat, _
        '            Locat, _
        '            Squad)
        If bolerror Then Exit Sub
        GenStatFile(bolerror, _
                    strerror, _
                    Stat, _
                    INI_Settings)
        Find_Moving_Locations(Stat, _
                              Locat, _
                              Station, _
                              Harbor, _
                              INI_Settings)
        GenMission(bolerror, _
                   strerror, _
                    Misweather, _
                    Miscloud, _
                    sMissFolder, _
                    Wind, _
                    House, _
                    BornPlace, _
                    ConvoyVeh, _
                    ConvoyInfo, _
                    StructInfo, _
                    StructList, _
                    Fact, _
                    Rocket, _
                    camsettings, _
                    MissSettings, _
                    Stat, _
                    Col, _
                    Ship, _
                    Train, _
                    Infantry, _
                    Locat, _
                    Station, _
                    Harbor, _
                    Road, _
                    ShipRoute, _
                    Rail, _
                    Trail, _
                    Bldg, _
                    Chief, _
                    ChiefMov, _
                    ChiefRd, _
                    DeadBridge, _
                    RoadWp, _
                    RailWP, _
                    SeaWP, _
                    TrailWP, _
                    Squad, _
                    UseSquad, _
                    MDS, _
                    MODS, _
                    Radar, _
                    RedCountry, _
                    BlueCountry, _
                    INI_Settings, _
                    MisTime, _
                    manufacture)
        If bolerror Then Exit Sub
        GenProperties(bolerror, _
                      strerror, _
                      sMissFolder, _
                      Misweather, _
                      Miscloud, _
                      Transport, _
                      Wind, _
                      BornPlace, _
                      camsettings, _
                      MissSettings, _
                      Infantry, _
                      Locat, _
                      strFrontLine, _
                      strACMove, _
                      strBdgDown, _
                      Squad, _
                      UseSquad, _
                      Weapon, _
                      SupplyAC, _
                      INI_Settings, _
                      MisTime)
        If bolerror Then Exit Sub
        If INI_Settings.Daemon = 1 Then GenSC_INI(sMissFolder, _
                                                    MissSettings, _
                                                    Squad, _
                                                    INI_Settings)
    End Sub

    Public Sub CopyPropFile(ByRef bolerror As Boolean, _
                        ByRef strerror As String, _
                        ByRef sMissFolder As String, _
                        ByRef INI_Settings As INI_Class)
        Dim PropTot As Integer
        Dim strSourceFile As String
        Dim strDestFile As String
        Dim filereader As StreamReader
        Dim sb As New StringBuilder
        strSourceFile = INI_Settings.sCampaign & "\dcgmission.properties"
        strDestFile = sMissFolder & "\dcgmission.properties"
        If My.Computer.FileSystem.FileExists(strSourceFile) Then
            filereader = My.Computer.FileSystem.OpenTextFileReader(strSourceFile)
            Do Until filereader.EndOfStream
                sb.AppendLine(filereader.ReadLine)
            Loop

            If PropTot > 0 Then
                Using outfile As New StreamWriter(strDestFile)
                    outfile.Write(sb.ToString())
                    outfile.Close()
                End Using
            End If
        End If
    End Sub
    Public Sub SaveDebriefs(ByRef strDebrief() As String, _
                                ByRef strFrontLine() As String, _
                                ByRef strACMove() As String, _
                                ByRef strBdgDown() As String, _
                                ByRef ini_settings As INI_Class)
        Dim intCount As Integer
        Dim strFile As String
        Dim sb As New StringBuilder
        If My.Computer.FileSystem.DirectoryExists(ini_settings.sCampaign) Then
            'Save Debrief
            strFile = ini_settings.sCampaign & "\debrief.txt"
            If strDebrief.Length > 1 Then
                For intCount = 1 To strDebrief.Length - 1
                    sb.AppendLine(strDebrief(intCount))
                Next
            Else
                sb.AppendLine("Nothing to report from last mission!")
            End If
            Using outfile As New StreamWriter(strFile)
                outfile.Write(sb.ToString())
                outfile.Close()
            End Using

            'Save AC Moves
            sb.Length = 0
            strFile = ini_settings.sCampaign & "\acmove.txt"
            If strACMove.Length > 1 Then
                For intCount = 1 To strACMove.Length - 1
                    sb.AppendLine(strACMove(intCount))
                Next
            Else
                sb.AppendLine("No squadrons moved!")
            End If
            Using outfile As New StreamWriter(strFile)
                outfile.Write(sb.ToString())
                outfile.Close()
            End Using

            'Save Contested
            sb.Length = 0
            strFile = ini_settings.sCampaign & "\frontline.txt"
            If strFrontLine.Length > 1 Then
                For intCount = 1 To strFrontLine.Length - 1
                    sb.AppendLine(strFrontLine(intCount))
                Next
            Else
                sb.AppendLine("No locations being contested!")
            End If
            Using outfile As New StreamWriter(strFile)
                outfile.Write(sb.ToString())
                outfile.Close()
            End Using

            'Save Bridges
            sb.Length = 0
            strFile = ini_settings.sCampaign & "\bridge.txt"
            If strBdgDown.Length > 1 Then
                For intCount = 1 To strBdgDown.Length - 1
                    sb.AppendLine(strBdgDown(intCount))
                Next
            Else
                sb.AppendLine("No bridges destroyed!")
            End If
            Using outfile As New StreamWriter(strFile)
                outfile.Write(sb.ToString())
                outfile.Close()
            End Using
        End If
    End Sub
    Private Sub LoadDebriefs(ByRef strDebrief() As String, _
                                ByRef strFrontLine() As String, _
                                ByRef strACMove() As String, _
                                ByRef strBdgDown() As String, _
                                ByRef INI_Settings As INI_Class)
        Dim strFile As String
        Dim filereader As IO.StreamReader
        If Dir(INI_Settings.sCampaign) = "" Then Exit Sub
        'Load Debrief
        strFile = INI_Settings.sCampaign & "\debrief.txt"
        ReDim strDebrief(0)
        If My.Computer.FileSystem.FileExists(strFile) Then
            filereader = My.Computer.FileSystem.OpenTextFileReader(strFile)
            Do Until filereader.EndOfStream

                ReDim Preserve strDebrief(strDebrief.Length)
                strDebrief(strDebrief.Length - 1) = filereader.ReadLine
            Loop
            filereader.Close()
        End If

        'Load AC Moves
        strFile = INI_Settings.sCampaign & "\acmove.txt"
        ReDim strACMove(0)
        If My.Computer.FileSystem.FileExists(strFile) Then
            filereader = My.Computer.FileSystem.OpenTextFileReader(strFile)
            Do Until filereader.EndOfStream
                ReDim Preserve strACMove(strACMove.Length)
                strACMove(strACMove.Length - 1) = filereader.ReadLine
            Loop
            filereader.Close()
        End If

        'Load Contested
        strFile = INI_Settings.sCampaign & "\frontline.txt"
        ReDim strFrontLine(0)
        If My.Computer.FileSystem.FileExists(strFile) Then
            filereader = My.Computer.FileSystem.OpenTextFileReader(strFile)
            Do Until filereader.EndOfStream
                ReDim Preserve strFrontLine(strFrontLine.Length)
                strFrontLine(strFrontLine.Length - 1) = filereader.ReadLine
            Loop
            filereader.Close()
        End If


        'Load Bridges
        strFile = INI_Settings.sCampaign & "\bridge.txt"
        ReDim strBdgDown(0)
        If My.Computer.FileSystem.FileExists(strFile) Then
            filereader = My.Computer.FileSystem.OpenTextFileReader(strFile)
            Do Until filereader.EndOfStream
                ReDim Preserve strBdgDown(strBdgDown.Length)
                strBdgDown(strBdgDown.Length - 1) = filereader.ReadLine
            Loop
            filereader.Close()
        End If
    End Sub

    Private Sub DestroyBridges(ByRef intDeadBridge As Integer, _
                                ByRef Bridge() As Brid)
        Dim strDeadBridge As String
        Dim intBridge As Integer
        Dim intTemp As Integer
        Dim strBridge As String
        strBridge = Bridge(intDeadBridge).ID
        strDeadBridge = " +3"
        intBridge = Int(Val(Mid(strBridge, 7)))
        intTemp = intBridge \ 64
        Select Case intTemp
            Case Is = 0
                strDeadBridge = strDeadBridge
            Case Is < 10
                strDeadBridge = Chr(48 + intTemp) & strDeadBridge
            Case Is < 36
                strDeadBridge = Chr(96 + intTemp - 9) & strDeadBridge
            Case Is < 62
                strDeadBridge = Chr(64 + intTemp - 35) & strDeadBridge
            Case Is = 62
                strDeadBridge = "-" & strDeadBridge
            Case Is = 63
                strDeadBridge = "+" & strDeadBridge
        End Select
        intTemp = intBridge Mod 64
        Select Case intTemp
            Case Is = 0
                strDeadBridge = "0" & strDeadBridge
            Case Is < 10
                strDeadBridge = Chr(48 + intTemp) & strDeadBridge
            Case Is < 36
                strDeadBridge = Chr(96 + intTemp - 9) & strDeadBridge
            Case Is < 62
                strDeadBridge = Chr(64 + intTemp - 35) & strDeadBridge
            Case Is = 62
                strDeadBridge = "-" & strDeadBridge
            Case Is = 63
                strDeadBridge = "+" & strDeadBridge
        End Select
        Bridge(intDeadBridge).Dead = strDeadBridge
    End Sub

    Private Sub LoadDeadBridge(ByRef DeadBridge() As String, _
                            ByRef INI_Settings As INI_Class)
        Dim strDBFile As String
        Dim intStart As Integer
        Dim strInput As String
        Dim filereader As IO.StreamReader
        strDBFile = INI_Settings.sCampaign & "\bridge.dcg"
        ReDim DeadBridge(0)
        If My.Computer.FileSystem.FileExists(strDBFile) Then
            filereader = My.Computer.FileSystem.OpenTextFileReader(strDBFile)
            Do Until filereader.EndOfStream
                strInput = filereader.ReadLine
                strInput = Trim(strInput)
                intStart = InStr(strInput, " ~~ ")
                If intStart > 0 Then
                    intStart = intStart + 4
                    If Len(strInput) > intStart Then
                        ReDim Preserve DeadBridge(DeadBridge.Length)
                        DeadBridge(DeadBridge.Length - 1) = Mid(strInput, intStart)
                    End If
                End If
            Loop
            filereader.Close()
        End If
    End Sub
    Public Sub LoadRocketFile(ByRef bolerror As Boolean, _
                            ByRef strerror As String, _
                            ByRef ConvoyInfo() As Convoy, _
                            ByRef Rocket() As RocketType, _
                            ByRef Locat() As Location, _
                            ByRef INI_Settings As INI_Class)

        Dim strRocketFile As String
        Dim strInput As String
        Dim intPos As Integer
        Dim intStart As Integer
        Dim intCon As Integer
        Dim filereader As IO.StreamReader
        strRocketFile = INI_Settings.sCampaign & "\rocket.dcg"
        If My.Computer.FileSystem.FileExists(strRocketFile) Then
            filereader = My.Computer.FileSystem.OpenTextFileReader(strRocketFile)
            Do Until filereader.EndOfStream
                strInput = filereader.ReadLine
                intStart = InStr(strInput, "_Rocket")
                If intStart > 0 Then
                    ReDim Preserve Rocket(Rocket.Length)
                    intStart = InStr(1, strInput, "X")
                    If intStart > 0 Then
                        Rocket(Rocket.Length - 1).Active = False
                    Else
                        Rocket(Rocket.Length - 1).Active = True
                    End If
                    intStart = 3
                    intPos = InStr(intStart, strInput, " ")
                    Rocket(Rocket.Length - 1).Ident = Trim(Mid(strInput, intStart, intPos - intStart))
                    intStart = intPos + 1
                    intPos = InStr(intStart, strInput, " ")
                    Rocket(Rocket.Length - 1).Unit = Trim(Mid(strInput, intStart, intPos - intStart))
                    intStart = intPos + 1
                    intPos = InStr(intStart, strInput, " ")
                    Rocket(Rocket.Length - 1).Side = Val(Mid(strInput, intStart, intPos - intStart))
                    intStart = intPos + 1
                    intPos = InStr(intStart, strInput, " ")
                    Rocket(Rocket.Length - 1).X = Val(Mid(strInput, intStart, intPos - intStart))
                    intStart = intPos + 1
                    intPos = InStr(intStart, strInput, " ")
                    Rocket(Rocket.Length - 1).Y = Val(Mid(strInput, intStart, intPos - intStart))
                    intStart = intPos + 1
                    intPos = InStr(intStart, strInput, " ")
                    Rocket(Rocket.Length - 1).Head = Val(Mid(strInput, intStart, intPos - intStart))
                    intStart = intPos + 1
                    intPos = InStr(intStart, strInput, " ")
                    Rocket(Rocket.Length - 1).Time = Val(Mid(strInput, intStart, intPos - intStart))
                    intStart = intPos + 1
                    intPos = InStr(intStart, strInput, " ")
                    Rocket(Rocket.Length - 1).Num = Val(Mid(strInput, intStart, intPos - intStart))
                    intStart = intPos + 1
                    intPos = InStr(intStart, strInput, " ")
                    Rocket(Rocket.Length - 1).Interval = Val(Mid(strInput, intStart, intPos - intStart))
                    intStart = intPos + 1
                    intPos = InStr(intStart, strInput, " ")
                    Rocket(Rocket.Length - 1).Xtgt = Val(Mid(strInput, intStart, intPos - intStart))
                    intStart = intPos + 1
                    Rocket(Rocket.Length - 1).Ytgt = Val(Mid(strInput, intStart))
                    FindWayPoint(Rocket(Rocket.Length - 1).X, _
                                    Rocket(Rocket.Length - 1).Y, _
                                    Rocket(Rocket.Length - 1).Loc, _
                                    Rocket(Rocket.Length - 1).intLoc, _
                                    Locat)
                    FindCon(Rocket(Rocket.Length - 1).Unit, _
                                    intCon, _
                                    ConvoyInfo)
                    If intCon < 1 Then
                        Rocket(Rocket.Length - 1).Size = 1
                        Rocket(Rocket.Length - 1).Curr = 1
                    Else
                        Rocket(Rocket.Length - 1).Size = ConvoyInfo(intCon).Size
                        Rocket(Rocket.Length - 1).Curr = ConvoyInfo(intCon).Size
                        Rocket(Rocket.Length - 1).Columns = ConvoyInfo(intCon).Columns
                        Rocket(Rocket.Length - 1).Supply = ConvoyInfo(intCon).Supply
                        Rocket(Rocket.Length - 1).Fuel = ConvoyInfo(intCon).Fuel
                        Rocket(Rocket.Length - 1).Troops = ConvoyInfo(intCon).Troops
                        Rocket(Rocket.Length - 1).ConType = intCon
                    End If
                End If
            Loop
            filereader.Close()
        End If
    End Sub

    Public Sub GenRocketFile(ByRef bolerror As Boolean, _
                            ByRef strerror As String, _
                            ByRef Rocket() As RocketType, _
                            ByRef INI_Settings As INI_Class)
        Dim intLine As Integer
        Dim strOutput As String
        Dim sb As New StringBuilder
        sb.AppendLine("[Rocket]")
        If Rocket.Length > 1 Then
            For intLine = 1 To Rocket.Length - 1
                With Rocket(intLine)
                    If .Active Then
                        strOutput = "  "
                    Else
                        strOutput = "X "
                    End If
                    strOutput = strOutput & .Ident & " " & _
                        .Unit & " " & _
                        Format(.Side, "0") & " " & _
                        Format(.X, "0.00") & " " & _
                        Format(.Y, "0.00") & " " & _
                        Format(.Head, "0.00") & " " & _
                        Format(.Time, "0.0") & " " & _
                        Format(.Num, "0") & " " & _
                        Format(.Interval, "0.0") & " " & _
                        Format(.Xtgt, "0.00") & " " & _
                        Format(.Ytgt, "0.00")
                End With
                sb.AppendLine(strOutput)
            Next
        End If
        'Using outfile As New StreamWriter(INI_Settings.sCampaign & "\rocket.dcg")
        'outfile.Write(sb.ToString())
        'outfile.Close()
        'End Using
        FileOpen(1, INI_Settings.sCampaign & "\rocket.dcg", OpenMode.Output, OpenAccess.Write, OpenShare.Shared)
        Print(1, sb.ToString)
        FileClose(1)
    End Sub

    Public Sub FindRocket(ByRef strID As String, _
                            ByRef intRocket As Integer, _
                                ByRef Rocket() As RocketType)
        intRocket = 0
        If Rocket.Length > 1 Then
            For intRocket = Rocket.Length - 1 To 0 Step -1
                If strID = Rocket(intRocket).Ident Then
                    Exit For
                End If
            Next
        End If
    End Sub
    Public Sub CleanUpRocket(ByRef bolerror As Boolean, _
                            ByRef strerror As String, _
                            ByRef Rocket() As RocketType, _
                            ByRef Locat() As Location)
        'This sub does a final check on rocketic objects and removes any at an enemy location
        Dim intRocketCnt As Integer
        If Rocket.Length < 2 Then
            Exit Sub
        End If
        For intRocketCnt = 1 To Rocket.Length - 1
            With Rocket(intRocketCnt)
                Select Case .Side
                    Case Is = 0
                        .Active = True
                    Case Is = 1
                        If Locat(.intLoc).Side = 2 Then .Active = False
                    Case Is = 2
                        If Locat(.intLoc).Side = 1 Then .Active = False
                End Select
            End With
        Next
    End Sub
    Public Sub UpdateRocket(ByRef bolerror As Boolean, _
                            ByRef strerror As String, _
                            ByRef Rocket() As RocketType, _
                            ByRef Locat() As Location, _
                            ByRef strDebrief() As String)
        Dim intRocketCnt As Integer
        If Rocket.Length < 2 Then
            Exit Sub
        End If
        For intRocketCnt = 1 To Rocket.Length - 1
            With Rocket(intRocketCnt)
                If .Curr / .Size < 0.5 Then
                    .Active = False

                    ReDim Preserve strDebrief(strDebrief.Length)
                    strDebrief(strDebrief.Length - 1) = .Unit & " at " & .Loc
                End If
                If Not .Active And _
                        Locat(.intLoc).Side > 0 And _
                        Locat(.intLoc).Supply > .Supply Then
                    If .Side = Locat(.intLoc).Side Then
                        .Active = True
                        Locat(.intLoc).Supply = Locat(.intLoc).Supply - .Supply
                    End If

                End If
            End With
        Next
    End Sub
    Public Sub PlaceColumn(ByRef intChief As Integer, _
                            ByRef ConvoyVeh(,) As String, _
                            ByRef convoyinfo() As Convoy, _
                            ByRef MissSettings As Mission, _
                            ByRef Col() As Column, _
                            ByRef Locat() As Location, _
                            ByRef Road() As Waypoint, _
                            ByRef Chief() As String, _
                            ByRef ChiefMov() As String, _
                            ByRef ChiefRd() As String, _
                            ByRef RoadWp() As String, _
                            ByRef INI_Settings As INI_Class, _
                            ByRef CamSettings As Campaign)

        Dim intUnit As Integer
        Dim dbX As Double
        Dim dbY As Double
        Dim intHead As Integer
        Dim intRd As Integer
        Dim strOutput As String

        If (Locat(Col(intChief).iTo).Side <> Col(intChief).Side Or _
                Locat(Col(intChief).iFrom).Side <> Col(intChief).Side) And _
                Col(intChief).Armor > 0 Then
            PlaceArmorColumnEngaged(intChief, _
                                    ConvoyVeh, _
                                    convoyinfo, _
                                    MissSettings, _
                                    Col, _
                                    Locat, _
                                    Road, _
                                    Chief, _
                                    ChiefMov, _
                                    ChiefRd, _
                                    RoadWp, _
                                    INI_Settings, _
                                    CamSettings)
            Exit Sub
        End If

        With Col(intChief)
            If .iFrom = .iTo Then 'Car at a named location
                If INI_Settings.iMovingDF > 0 And _
                     ((.Side = 1 And Locat(.iFrom).RedRoad > 0) Or _
                      (.Side = 2 And Locat(.iFrom).BlueRoad > 0)) Then
                    PlaceTankAtLocationMoving(intChief, _
                                        Locat, _
                                        MissSettings, _
                                        Col, _
                                        Road, _
                                        ChiefMov, _
                                        ChiefRd, _
                                        RoadWp, _
                                        INI_Settings)
                Else
                    If .Side = 1 Then
                        dbX = Locat(.iFrom).AlliedX
                        dbY = Locat(.iFrom).AlliedY
                        intHead = Locat(.iFrom).AlliedH
                    Else
                        dbX = Locat(.iFrom).AxisX
                        dbY = Locat(.iFrom).AxisY
                        intHead = Locat(.iFrom).AxisH
                    End If

                    If .Side = 1 Then
                        MoveCoor(Locat(.iFrom).AlliedX, _
                                    Locat(.iFrom).AlliedY, _
                                    Locat(.iFrom).AlliedH, _
                                            INI_Settings.sngStaticSep * (1 + .Size))
                    Else
                        MoveCoor(Locat(.iFrom).AxisX, _
                                    Locat(.iFrom).AxisY, _
                                    Locat(.iFrom).AxisH, _
                                    INI_Settings.sngStaticSep * (1 + .Size))
                    End If
                    For intUnit = 1 To .Curr

                        strOutput = "  " & .Ident & Format(intUnit - 1, "0") & _
                                    " " & ConvoyVeh(intUnit, .ConType) & _
                                    " " & Format(.Side, "0") & _
                                    " " & Format(dbX, "########.00") & _
                                    " " & Format(dbY, "########.00") & _
                                    " " & Format(intHead + 90, "##0.0")
                        If InStr(strOutput, ".artillery") > 0 Then
                            strOutput = strOutput & _
                                    " " & Format(INI_Settings.sngDelay, "0.0") & _
                                    " " & Format(INI_Settings.sngRange, "0")
                        Else
                            strOutput = strOutput & " 0.0"
                        End If
                        MoveCoor(dbX, _
                                dbY, _
                                intHead, _
                                INI_Settings.sngStaticSep)

                        ReDim Preserve Chief(Chief.Length)
                        Chief(Chief.Length - 1) = strOutput
                    Next
                End If
            Else 'Column between named locations

                For intRd = Road.Length - 1 To 1 Step -1
                    If (Road(intRd).iFrom = .iTo And _
                            Road(intRd).iTo = .iFrom) Or _
                            (Road(intRd).iFrom = .iFrom And _
                            Road(intRd).iTo = .iTo) Then
                        If .Side = 1 Then
                            dbX = Road(intRd).AlliedX
                            dbY = Road(intRd).AlliedY
                            intHead = Road(intRd).AlliedH
                        Else
                            dbX = Road(intRd).AxisX
                            dbY = Road(intRd).AxisY
                            intHead = Road(intRd).AxisH
                        End If
                        Exit For
                    End If
                Next

                If intRd > 0 Then 'imovingdf = 1 is close to front line, greater all move
                    If (Locat(.iFrom).Moving) And _
                              (Road(intRd).iEnd - Road(intRd).Start > 2 * (INI_Settings.ColSpawn + 3)) And _
                              ((Road(intRd).iFrom = .iFrom And Road(intRd).AxisSP <= INI_Settings.ColSpawn) Or _
                              (Road(intRd).iTo = .iFrom And Road(intRd).AlliedSP < INI_Settings.ColSpawn)) Then
                        PlaceCarMoving(intChief, _
                                       intRd, _
                                       convoyinfo, _
                                       MissSettings, _
                                       Col, _
                                       Road, _
                                       ChiefMov, _
                                       ChiefRd, _
                                       RoadWp, _
                                       INI_Settings)
                    Else
                        If .Side = 1 Then
                            MoveCoor(Road(intRd).AlliedX, _
                                Road(intRd).AlliedY, _
                                Road(intRd).AlliedH, _
                                INI_Settings.sngStaticSep * (1 + .Size))
                        Else
                            MoveCoor(Road(intRd).AxisX, _
                                Road(intRd).AxisY, _
                                Road(intRd).AxisH, _
                                INI_Settings.sngStaticSep * (1 + .Size))
                        End If
                        For intUnit = 1 To .Curr
                            strOutput = "  " & .Ident & Format(intUnit - 1, "0") & _
                                " " & ConvoyVeh(intUnit, .ConType) & _
                                " " & Format(.Side, "0") & _
                                " " & Format(dbX, "#######0.00") & _
                                " " & Format(dbY, "#######0.00") & _
                                " " & Format(intHead + 90, "##0.0")
                            If InStr(strOutput, ".artillery") > 0 Then
                                strOutput = strOutput & _
                                    " " & Format(INI_Settings.sngDelay, "0.0") & _
                                    " " & Format(INI_Settings.sngRange, "0")
                            Else
                                strOutput = strOutput & " 0.0"
                            End If
                            MoveCoor(dbX, _
                                dbY, _
                                intHead, _
                                INI_Settings.sngStaticSep)

                            ReDim Preserve Chief(Chief.Length)
                            Chief(Chief.Length - 1) = strOutput
                        Next
                    End If
                End If
            End If
        End With
    End Sub
    Public Sub PlaceArtillery(ByRef intChief As Integer, _
                                ByRef ConvoyVeh(,) As String, _
                                ByRef Col() As Column, _
                                ByRef Locat() As Location, _
                                ByRef Road() As Waypoint, _
                                ByRef Chief() As String, _
                                ByRef INI_Settings As INI_Class)
        Dim intUnit As Integer
        Dim dbX As Double
        Dim dbY As Double
        Dim intHead As Integer
        Dim intRd As Integer
        Dim strOutput As String
        If Locat(Col(intChief).iTo).Side <> Col(intChief).Side Or _
                Locat(Col(intChief).iFrom).Side <> Col(intChief).Side Then
            PlaceArtEngage(intChief, _
                           ConvoyVeh, _
                           Col, _
                           Locat, _
                           Road, _
                           Chief, _
                            INI_Settings)
            Exit Sub
        End If
        For intRd = 1 To Road.Length - 1
            If Col(intChief).iFrom = Road(intRd).iFrom Or _
                    Col(intChief).iFrom = Road(intRd).iTo Or _
                    Col(intChief).iTo = Road(intRd).iFrom Or _
                    Col(intChief).iTo = Road(intRd).iTo Then
                If Locat(Road(intRd).iTo).Side <> Col(intChief).Side Or _
                        Locat(Road(intRd).iFrom).Side <> Col(intChief).Side Then
                    PlaceArtEngage(intChief, _
                                   ConvoyVeh, _
                                   Col, _
                                   Locat, _
                                   Road, _
                                   Chief, _
                                   INI_Settings)
                    Exit Sub
                End If
            End If
        Next
        With Col(intChief)
            If .iFrom = .iTo Then 'Artillery at a named location
                If .Side = 1 Then
                    dbX = Locat(.iFrom).AlliedX
                    dbY = Locat(.iFrom).AlliedY
                    intHead = Locat(.iFrom).AlliedH
                Else
                    dbX = Locat(.iFrom).AxisX
                    dbY = Locat(.iFrom).AxisY
                    intHead = Locat(.iFrom).AxisH
                End If

                If .Side = 1 Then
                    MoveCoor(Locat(.iFrom).AlliedX, _
                                Locat(.iFrom).AlliedY, _
                                Locat(.iFrom).AlliedH, _
                                INI_Settings.sngStaticSep * (1 + .Size))
                Else
                    MoveCoor(Locat(.iFrom).AxisX, _
                                Locat(.iFrom).AxisY, _
                                Locat(.iFrom).AxisH, _
                                INI_Settings.sngStaticSep * (1 + .Size))
                End If
                For intUnit = 1 To .Curr

                    strOutput = "  " & .Ident & Format(intUnit - 1, "0") & _
                                " " & ConvoyVeh(intUnit, .ConType) & _
                                " " & Format(.Side, "0") & _
                                " " & Format(dbX, "########.00") & _
                                " " & Format(dbY, "########.00")
                    If InStr(strOutput, ".artillery") > 0 Then
                        strOutput = strOutput & _
                                " " & Format(intHead + 270, "##0.0") & _
                                " " & Format(INI_Settings.sngDelay, "0.0") & _
                                " " & Format(INI_Settings.sngRange, "0")
                    Else
                        strOutput = strOutput & _
                                    " " & Format(intHead + 90, "##0.0") & _
                                    " 0.0"
                    End If
                    If InStr(strOutput, ".artillery.Artillery") > 0 Then
                        strOutput = Replace(strOutput, ".artillery.Artillery", ".stationary.Stationary")
                    End If
                    MoveCoor(dbX, _
                            dbY, _
                            intHead, _
                            INI_Settings.sngStaticSep)

                    ReDim Preserve Chief(Chief.Length)
                    Chief(Chief.Length - 1) = strOutput
                Next

            Else 'Car between named locations
                For intRd = Road.Length - 1 To 1 Step -1
                    If (Road(intRd).iFrom = .iTo And _
                            Road(intRd).iTo = .iFrom) Or _
                            (Road(intRd).iFrom = .iFrom And _
                            Road(intRd).iTo = .iTo) Then
                        If .Side = 1 Then
                            dbX = Road(intRd).AlliedX
                            dbY = Road(intRd).AlliedY
                            intHead = Road(intRd).AlliedH
                        Else
                            dbX = Road(intRd).AxisX
                            dbY = Road(intRd).AxisY
                            intHead = Road(intRd).AxisH
                        End If
                        Exit For
                    End If
                Next
                If intRd > 0 Then
                    If .Side = 1 Then
                        MoveCoor(Road(intRd).AlliedX, _
                            Road(intRd).AlliedY, _
                            Road(intRd).AlliedH, _
                            INI_Settings.sngStaticSep * (1 + .Size))
                    Else
                        MoveCoor(Road(intRd).AxisX, _
                            Road(intRd).AxisY, _
                            Road(intRd).AxisH, _
                            INI_Settings.sngStaticSep * (1 + .Size))
                    End If
                    For intUnit = 1 To .Curr
                        strOutput = "  " & .Ident & Format(intUnit - 1, "0") & _
                                " " & ConvoyVeh(intUnit, .ConType) & _
                                " " & Format(.Side, "0") & _
                                " " & Format(dbX, "#######0.00") & _
                                " " & Format(dbY, "#######0.00")
                        If InStr(strOutput, ".artillery") > 0 Then
                            strOutput = strOutput & _
                                " " & Format(intHead + 270, "##0.0") & _
                            " " & Format(INI_Settings.sngDelay, "0.0") & _
                            " " & Format(INI_Settings.sngRange, "0")
                        Else
                            strOutput = strOutput & _
                                " " & Format(intHead + 90, "##0.0") & _
                                " 0.0"
                        End If
                        If InStr(strOutput, ".artillery.Artillery") > 0 Then
                            strOutput = Replace(strOutput, ".artillery.Artillery", ".stationary.Stationary")
                        End If
                        MoveCoor(dbX, _
                            dbY, _
                            intHead, _
                            INI_Settings.sngStaticSep)

                        ReDim Preserve Chief(Chief.Length)
                        Chief(Chief.Length - 1) = strOutput
                    Next
                End If
            End If
        End With
    End Sub

    Public Sub PlaceArtEngage(ByRef intChief As Integer, _
                                ByRef ConvoyVeh(,) As String, _
                                ByRef Col() As Column, _
                                ByRef Locat() As Location, _
                                ByRef Road() As Waypoint, _
                                ByRef Chief() As String, _
                                ByRef INI_Settings As INI_Class)
        Dim intUnit As Integer
        Dim dbX As Double
        Dim dbY As Double
        Dim intHead As Integer
        Dim intRd As Integer
        Dim strOutput As String
        With Col(intChief)
            If .iFrom = .iTo Then 'Artillery at a named location
                If .Side = 1 Then
                    dbX = Locat(.iFrom).AlliedX
                    dbY = Locat(.iFrom).AlliedY
                    intHead = Locat(.iFrom).AlliedH
                Else
                    dbX = Locat(.iFrom).AxisX
                    dbY = Locat(.iFrom).AxisY
                    intHead = Locat(.iFrom).AxisH
                End If

                If .Side = 1 Then
                    MoveCoor(Locat(.iFrom).AlliedX, _
                                Locat(.iFrom).AlliedY, _
                                Locat(.iFrom).AlliedH, _
                                INI_Settings.sngStaticSep * 5)
                Else
                    MoveCoor(Locat(.iFrom).AxisX, _
                                Locat(.iFrom).AxisY, _
                                Locat(.iFrom).AxisH, _
                                INI_Settings.sngStaticSep * 5)
                End If
                For intUnit = 1 To .Curr

                    strOutput = "  " & .Ident & Format(intUnit - 1, "0") & _
                                " " & ConvoyVeh(intUnit, .ConType) & _
                                " " & Format(.Side, "0") & _
                                " " & Format(dbX, "0.00") & _
                                " " & Format(dbY, "0.00")
                    If InStr(strOutput, ".artillery") > 0 Then
                        strOutput = strOutput & _
                                " " & Format(intHead + 90, "##0.0") & _
                                " " & Format(INI_Settings.sngDelay, "0.0") & _
                                " " & Format(INI_Settings.sngRange, "0")
                    Else
                        strOutput = strOutput & _
                                    " " & Format(intHead + 90, "0.0") & _
                                    " 0.0"
                    End If
                    MoveCoor(dbX, _
                            dbY, _
                            intHead + 90, _
                            INI_Settings.sngStaticSep)

                    ReDim Preserve Chief(Chief.Length)
                    Chief(Chief.Length - 1) = strOutput
                Next

            Else 'Car between named locations
                For intRd = Road.Length - 1 To 1 Step -1
                    If (Road(intRd).iFrom = .iTo And _
                            Road(intRd).iTo = .iFrom) Or _
                            (Road(intRd).iFrom = .iFrom And _
                            Road(intRd).iTo = .iTo) Then
                        If .Side = 1 Then
                            dbX = Road(intRd).AlliedX
                            dbY = Road(intRd).AlliedY
                            intHead = Road(intRd).AlliedH
                        Else
                            dbX = Road(intRd).AxisX
                            dbY = Road(intRd).AxisY
                            intHead = Road(intRd).AxisH
                        End If
                        Exit For
                    End If
                Next
                If intRd > 0 Then
                    If .Side = 1 Then
                        MoveCoor(Road(intRd).AlliedX, _
                            Road(intRd).AlliedY, _
                            Road(intRd).AlliedH, _
                            INI_Settings.sngStaticSep * (5 + .Size))
                    Else
                        MoveCoor(Road(intRd).AxisX, _
                            Road(intRd).AxisY, _
                            Road(intRd).AxisH, _
                            INI_Settings.sngStaticSep * (5 + .Size))
                    End If
                    For intUnit = 1 To .Curr
                        strOutput = "  " & .Ident & Format(intUnit - 1, "0") & _
                                " " & ConvoyVeh(intUnit, .ConType) & _
                                " " & Format(.Side, "0") & _
                                " " & Format(dbX, "0.00") & _
                                " " & Format(dbY, "0.00")
                        If InStr(strOutput, ".artillery") > 0 Then
                            strOutput = strOutput & _
                                " " & Format(intHead + 90, "0.0") & _
                                " " & Format(INI_Settings.sngDelay, "0.0") & _
                                " " & Format(INI_Settings.sngRange, "0")
                        Else
                            strOutput = strOutput & _
                                " " & Format(intHead + 90, "0.0") & _
                                " 0.0"
                        End If
                        MoveCoor(dbX, _
                            dbY, _
                            intHead + 90, _
                            INI_Settings.sngStaticSep)

                        ReDim Preserve Chief(Chief.Length)
                        Chief(Chief.Length - 1) = strOutput
                    Next
                End If
            End If
        End With
    End Sub
    Public Sub GenColLocFile(ByRef bolerror As Boolean, _
                            ByRef strerror As String, _
                            ByRef ColLoc() As String, _
                            ByRef INI_Settings As INI_Class)
        Dim intLine As Integer
        Dim sb As New StringBuilder
        If ColLoc.Length > 1 Then
            For intLine = 1 To ColLoc.Length - 1
                sb.AppendLine(ColLoc(intLine))
            Next
            Using outfile As New StreamWriter(INI_Settings.sCampaign & "\colloc.dcg")
                outfile.Write(sb.ToString())
                outfile.Close()
            End Using
        End If
    End Sub
    Public Sub PlaceRocketStat(ByRef intRocket As Integer, _
                                ByRef sb As StringBuilder, _
                                ByRef ConvoyVeh(,) As String, _
                                ByRef Rocket() As RocketType)
        Dim strOutput As String
        Dim intCount As Integer
        With Rocket(intRocket)
            If .Active Then
                For intCount = 1 To .Size
                    strOutput = "  " & .Ident & Format(intCount, "0") & " " & _
                        ConvoyVeh(intCount, .ConType) & " " & _
                        Format(.Side, "0") & " " & _
                        Format(.X, "0.00") & " " & _
                        Format(.Y, "0.00") & " " & _
                        Format(.Head, "0.00")
                    sb.AppendLine(strOutput)
                Next
            End If
        End With
    End Sub

    Public Sub GenBridgeFile(ByRef bolerror As Boolean, _
                            ByRef strerror As String, _
                            ByRef Bridge() As Brid, _
                            ByRef MissSettings As Mission, _
                            ByRef INI_Settings As INI_Class)
        Dim intLine As Integer
        Dim sb As New StringBuilder
        sb.AppendLine("[Bridge]")
        If Bridge.Length > 1 And MissSettings.Bridge > 1 Then
            For intLine = 1 To Bridge.Length - 1
                With Bridge(intLine)
                    sb.AppendLine("  " & .ID & " " & _
                        .sFrom & " " & _
                        .sTo & " " & _
                        Format(.X, "0.00") & " " & _
                        Format(.Y, "0.00") & _
                        " ~~ " & .Dead)
                End With
            Next
        End If
        'Using outfile As New StreamWriter(INI_Settings.sCampaign & "\bridge.dcg")
        'outfile.Write(sb.ToString())
        'outfile.Close()
        'End Using
        FileOpen(1, INI_Settings.sCampaign & "\bridge.dcg", OpenMode.Output, OpenAccess.Write, OpenShare.Shared)
        Print(1, sb.ToString)
        FileClose(1)
    End Sub

    Public Sub RepairBridges(ByRef bolerror As Boolean, _
                                ByRef strerror As String, _
                                ByRef Bridge() As Brid, _
                                ByRef Col() As Column, _
                                ByRef strDebrief() As String)
        Dim intCount As Integer
        Dim intCnt2 As Integer
        Dim strOutput As String
        Dim intStart As Integer
        If Col.Length < 2 Then Exit Sub
        If Bridge.Length > 1 Then
            For intCount = 1 To Bridge.Length - 1
                For intCnt2 = 1 To Col.Length - 1
                    With Col(intCnt2)
                        If .BR > 0 Then
                            If (.sFrom = Bridge(intCount).sTo And _
                                    .sTo = Bridge(intCount).sFrom) Or _
                                    (.sTo = Bridge(intCount).sTo And _
                                    .sFrom = Bridge(intCount).sFrom) Then
                                Bridge(intCount).sTo = "Repaired"
                                Bridge(intCount).sFrom = "Repaired"
                                Bridge(intCount).iTo = 0
                                Bridge(intCount).iFrom = 0
                                Bridge(intCount).Dead = ""

                                ReDim Preserve strDebrief(strDebrief.Length)
                                intStart = InStr(.Unit, ".") + 1
                                strOutput = Bridge(intCount).ID & " repaired by " & .Ident
                                strDebrief(strDebrief.Length - 1) = strOutput
                            End If
                        End If
                    End With
                Next
            Next
        End If
    End Sub
    Public Sub FindPilot(ByRef sPilot As String, _
                         ByRef iPilot As Integer, _
                         ByRef Pilot() As Plt)
        'Finds Pilot or Adds him if he does not exist
        'If InStr(sPilot, ":") > 0 Then Stop
        sPilot = Trim(sPilot)
        If sPilot = "" Then
            iPilot = 0
            Exit Sub
        End If
        For iPilot = Pilot.Length - 1 To 1 Step -1
            If sPilot = Pilot(iPilot).Name Then
                Exit For
            End If
        Next
        If iPilot < 1 Then
            ReDim Preserve Pilot(Pilot.Length)
            Pilot(Pilot.Length - 1).Name = sPilot
            iPilot = Pilot.Length - 1
        End If
    End Sub
    Public Sub UpdateHarbors(ByRef Ship() As Column, _
                                ByRef Harbor() As Location)
        'Sets the side of harbors
        Dim intCntHar As Integer
        Dim intCntShip As Integer
        If Ship.Length < 2 Then Exit Sub
        If Harbor.Length < 2 Then Exit Sub
        For intCntHar = 1 To Harbor.Length - 1
            Harbor(intCntHar).Allied = 0
            Harbor(intCntHar).Axis = 0
        Next
        For intCntShip = 1 To Ship.Length - 1
            If Ship(intCntShip).iFrom > 0 Then
                If Ship(intCntShip).Side = 1 Then
                    Harbor(Ship(intCntShip).iFrom).Allied = _
                        Harbor(Ship(intCntShip).iFrom).Allied + Int(ptShip * Ship(intCntShip).Curr)
                Else
                    Harbor(Ship(intCntShip).iFrom).Axis = _
                        Harbor(Ship(intCntShip).iFrom).Axis + Int(ptShip * Ship(intCntShip).Curr)
                End If
            End If
        Next
        For intCntHar = 1 To Harbor.Length - 1
            With Harbor(intCntHar)
                If .Allied > 0 And .Axis > 0 Then .Side = 0
                If .Allied > 0 And .Axis < 1 Then .Side = 1
                If .Allied < 1 And .Axis > 0 Then .Side = 2
            End With
        Next
    End Sub
    Public Sub MoveShipCoor(ByRef dbX As Double, _
                         ByRef dbY As Double, _
                        ByRef Head As Integer, _
                        ByRef intDist As Integer)
        Dim X As Double
        Dim Y As Double
        Dim sngRnd As Single
        Do
            If Head >= 0 Or Head <= 360 Then Exit Do
            If Head > 360 Then Head = Head - 360
            If Head < 0 Then Head = Head + 360
        Loop

        Y = Math.Cos(Head * 3.14 / 180) * intDist
        X = Math.Sin(Head * 3.14 / 180) * intDist
        dbX = dbX + X
        dbY = dbY + Y
        sngRnd = Rnd()
        If sngRnd > 0.5 Then
            Head = Head - 90
        Else
            Head = Head + 90
        End If
        Do
            If Head >= 0 Or Head <= 360 Then Exit Do
            If Head > 360 Then Head = Head - 360
            If Head < 0 Then Head = Head + 360
        Loop

        Y = Math.Cos(Head * 3.14 / 180) * intDist / 2
        X = Math.Sin(Head * 3.14 / 180) * intDist / 2
        dbX = dbX + X
        dbY = dbY + Y
    End Sub
    Public Sub LoadWeaponFile(ByRef bolerror As Boolean, _
                            ByRef strerror As String, _
                            ByRef Squad() As Squad_Type, _
                            ByRef Weapon() As Weap, _
                            ByRef INI_Settings As INI_Class, _
                            ByRef AC_New() As AC_Type)
        Dim strWeaponFile As String
        Dim strInput As String
        Dim intEnd As Integer
        Dim intStart As Integer
        Dim intWeapon As Integer
        Dim intSquad As Integer
        Dim iAC As Integer
        Dim filereader As IO.StreamReader
        If Squad.Length < 2 Then Exit Sub
        strWeaponFile = INI_Settings.sCampaign & "\weapons.dcg"
        If My.Computer.FileSystem.FileExists(strWeaponFile) Then
            filereader = My.Computer.FileSystem.OpenTextFileReader(strWeaponFile)
            Do Until filereader.EndOfStream
                strInput = filereader.ReadLine
                If InStr(strInput, "[") > 0 And _
                            InStr(strInput, "]") > 0 And _
                            InStr(strInput, "]") > InStr(strInput, "[") Then
                    ReDim Preserve Weapon(Weapon.Length)
                    intStart = InStr(strInput, "[")
                    intEnd = InStr(strInput, "]")
                    Weapon(Weapon.Length - 1).AC = Mid(strInput, intStart + 1, intEnd - intStart - 1)
                    For iAC = 1 To AC_New.Length - 1
                        If Weapon(Weapon.Length - 1).AC = AC_New(iAC).Coop Then
                            Weapon(Weapon.Length - 1).AC = AC_New(iAC).DF
                            Exit For
                        End If
                        If Weapon(Weapon.Length - 1).AC = AC_New(iAC).DF Then Exit For
                    Next
                    Weapon(Weapon.Length - 1).Weapon = ";"
                Else
                    If strInput <> "" Then
                        Weapon(Weapon.Length - 1).Weapon = Weapon(Weapon.Length - 1).Weapon & Trim(strInput) & ";"
                    End If
                End If
            Loop
            filereader.Close()
            If Weapon.Length > 1 Then
                For intWeapon = 1 To Weapon.Length - 1
                    For intSquad = 1 To Squad.Length - 1
                        If Squad(intSquad).Coop = Weapon(intWeapon).AC Or _
                            Squad(intSquad).DF = Weapon(intWeapon).AC Then
                            Squad(intSquad).Weapon = Weapon(intWeapon).Weapon
                        End If
                    Next
                Next
            End If
        End If
    End Sub

    Public Sub PlaceTank_Engaged(ByRef intChief As Integer, _
                                    ByRef MissSettings As Mission, _
                                    ByRef Col() As Column, _
                                    ByRef Locat() As Location, _
                                    ByRef Road() As Waypoint, _
                                    ByRef Chief() As String, _
                                    ByRef ChiefMov() As String, _
                                    ByRef ChiefRd() As String, _
                                    ByRef RoadWp() As String, _
                                    ByRef INI_Settings As INI_Class, _
                                    ByRef CamSettings As Campaign)
        Dim intUnit As Integer
        Dim dbX As Double
        Dim dbY As Double
        Dim intHead As Integer
        Dim strUnit As String
        Dim intRd As Integer
        Dim intDir As Integer
        Dim intRnd As Integer
        Dim intStart As Integer
        Dim strOutput As String
        With Col(intChief)
            If .iFrom = .iTo Then 'Tanks at a named location
                If INI_Settings.iMovingDF > 0 And _
                    ((.Side = 1 And Locat(.iFrom).RedRoad > 0) Or _
                        (.Side = 2 And Locat(.iFrom).BlueRoad > 0)) Then
                    PlaceTankAtLocationMoving(intChief, _
                                        Locat, _
                                        MissSettings, _
                                        Col, _
                                        Road, _
                                        ChiefMov, _
                                        ChiefRd, _
                                        RoadWp, _
                                        INI_Settings)
                Else
                    If .Side = 1 Then
                        dbX = Locat(.iFrom).AlliedX
                        dbY = Locat(.iFrom).AlliedY
                        intHead = Locat(.iFrom).AlliedH
                        MoveCoor(Locat(.iFrom).AlliedX, _
                                    Locat(.iFrom).AlliedY, _
                                    Locat(.iFrom).AlliedH, _
                                    INI_Settings.sngStaticSep * 5)
                    Else
                        dbX = Locat(.iFrom).AxisX
                        dbY = Locat(.iFrom).AxisY
                        intHead = Locat(.iFrom).AxisH
                        MoveCoor(Locat(.iFrom).AxisX, _
                                    Locat(.iFrom).AxisY, _
                                    Locat(.iFrom).AxisH, _
                                    INI_Settings.sngStaticSep * 5)
                    End If


                    intStart = InStr(.Unit, "-")
                    intStart = intStart + 1
                    strUnit = Trim(Mid(.Unit, intStart))
                    If InStr(strUnit, "SU-") > 0 Then strUnit = Replace(strUnit, "SU-", "SU")
                    strUnit = "vehicles.artillery.Artillery$" & strUnit
                    intDir = -1
                    intRnd = Int(Rnd() * INI_Settings.sngStaticSep * 4)
                    MoveCoor(dbX, _
                            dbY, _
                            intHead + (90 * intDir), _
                            intRnd)
                    For intUnit = 1 To .Size
                        MoveCoor(dbX, _
                                dbY, _
                                intHead + (90 * intDir), _
                                INI_Settings.sngStaticSep * 2)
                        strOutput = "  " & .Ident & Format(intUnit - 1, "0") & _
                                    " " & strUnit & _
                                    " " & Format(.Side, "0") & _
                                    " " & Format(dbX, "########.00") & _
                                    " " & Format(dbY, "########.00") & _
                                    " " & Format(intHead + 90, "##0.0")
                        If InStr(strOutput, ".artillery") > 0 Then
                            strOutput = strOutput & _
                                    Format(INI_Settings.sngTankDly, " 0.0") & " " & _
                                    Format(INI_Settings.sngTankRng, "0")
                        Else
                            strOutput = strOutput & " 0.0"
                        End If

                        ReDim Preserve Chief(Chief.Length)
                        Chief(Chief.Length - 1) = strOutput
                    Next
                End If
            Else
                For intRd = Road.Length - 1 To 1 Step -1
                    If (Road(intRd).iFrom = .iTo And _
                            Road(intRd).iTo = .iFrom) Or _
                            (Road(intRd).iFrom = .iFrom And _
                            Road(intRd).iTo = .iTo) Then
                        If .Side = 1 Then
                            dbX = Road(intRd).AlliedX
                            dbY = Road(intRd).AlliedY
                            intHead = Road(intRd).AlliedH
                        Else
                            dbX = Road(intRd).AxisX
                            dbY = Road(intRd).AxisY
                            intHead = Road(intRd).AxisH
                        End If
                        Exit For
                    End If
                Next
                If intRd > 1 Then
                    If (INI_Settings.iMovingDF > 0) And _
                              (Road(intRd).iEnd - Road(intRd).Start > 2 * (INI_Settings.ColSpawn + 3)) And _
                              ((Road(intRd).iFrom = .iFrom And Road(intRd).AxisSP <= INI_Settings.ColSpawn) Or _
                              (Road(intRd).iTo = .iFrom And Road(intRd).AlliedSP < INI_Settings.ColSpawn)) Then
                        PlaceTankMoving(intChief, _
                                        intRd, _
                                        MissSettings, _
                                        Col, _
                                        Road, _
                                        ChiefMov, _
                                        ChiefRd, _
                                        RoadWp, _
                                        INI_Settings)
                    Else
                        If .Side = 1 Then
                            MoveCoor(Road(intRd).AlliedX, _
                                Road(intRd).AlliedY, _
                                Road(intRd).AlliedH, _
                                INI_Settings.sngStaticSep * 2)
                        Else
                            MoveCoor(Road(intRd).AxisX, _
                                Road(intRd).AxisY, _
                                Road(intRd).AxisH, _
                                INI_Settings.sngStaticSep * 2)
                        End If
                        intStart = InStr(.Unit, "-")
                        intStart = intStart + 1
                        strUnit = Trim(Mid(.Unit, intStart))
                        If InStr(strUnit, "SU-") > 0 Then strUnit = Replace(strUnit, "SU-", "SU")
                        strUnit = "vehicles.artillery.Artillery$" & strUnit
                        intDir = -1
                        intRnd = Int(Rnd() * INI_Settings.sngStaticSep * 3)
                        MoveCoor(dbX, _
                            dbY, _
                            intHead + (90 * intDir), _
                            intRnd)
                        For intUnit = 1 To .Size
                            MoveCoor(dbX, _
                                dbY, _
                                intHead + (90 * intDir), _
                                INI_Settings.sngStaticSep)
                            strOutput = "  " & .Ident & Format(intUnit - 1, "0") & _
                                " " & strUnit & _
                                " " & Format(.Side, "0") & _
                                " " & Format(dbX, "########.00") & _
                                " " & Format(dbY, "########.00") & _
                                " " & Format(intHead + 90, "##0.0")
                            If InStr(strOutput, ".artillery") > 0 Then
                                strOutput = strOutput & _
                                    Format(INI_Settings.sngTankDly, " 0.0") & " " & _
                                    Format(INI_Settings.sngTankRng, "0")
                            Else
                                strOutput = strOutput & " 0.0"
                            End If

                            ReDim Preserve Chief(Chief.Length)
                            Chief(Chief.Length - 1) = strOutput
                        Next
                    End If
                End If
            End If
        End With
    End Sub

    Public Sub LoadConditionsFile(ByRef bolerror As Boolean, _
                        ByRef strerror As String, _
                        ByRef MisWeather As Integer, _
                        ByRef MisCloud As Integer, _
                        ByRef Wind As Weather, _
                        ByRef INI_Settings As INI_Class, _
                        ByRef MisTime As Single)
        Dim strCondFile As String
        Dim strInput As String = ""
        Dim strValue As String = ""
        Dim intStart As Integer
        Dim filereader As IO.StreamReader
        With Wind
            .Direction = 0
            .Gust = 0
            .Top = 500
            .Turbulence = 0
            .Velocity = 0
        End With
        strCondFile = INI_Settings.sCampaign & "\conditions.dcg"
        If My.Computer.FileSystem.FileExists(strCondFile) Then
            filereader = My.Computer.FileSystem.OpenTextFileReader(strCondFile)
            Do Until filereader.EndOfStream
                strInput = filereader.ReadLine
                intStart = InStr(strInput, "Time=")
                If intStart > 0 Then
                    FindValue(strInput, strValue)
                    MisTime = Val(strValue)
                End If

                intStart = InStr(strInput, "Weather=")
                If intStart > 0 Then
                    FindValue(strInput, strValue)
                    MisWeather = Val(strValue)
                End If

                intStart = InStr(strInput, "Cloud=")
                If intStart > 0 Then
                    FindValue(strInput, strValue)
                    MisCloud = Val(strValue)
                End If
                intStart = InStr(strInput, "Velocity=")
                If intStart > 0 Then
                    FindValue(strInput, strValue)
                    Wind.Velocity = Val(strValue)
                End If
                intStart = InStr(strInput, "Direction=")
                If intStart > 0 Then
                    FindValue(strInput, strValue)
                    Wind.Direction = Val(strValue)
                End If
                intStart = InStr(strInput, "Top=")
                If intStart > 0 Then
                    FindValue(strInput, strValue)
                    Wind.Top = Val(strValue)
                End If
                intStart = InStr(strInput, "Turbulence=")
                If intStart > 0 Then
                    FindValue(strInput, strValue)
                    Wind.Turbulence = Val(strValue)
                End If
                intStart = InStr(strInput, "Gust=")
                If intStart > 0 Then
                    FindValue(strInput, strValue)
                    Wind.Gust = Val(strValue)
                End If
            Loop
            filereader.Close()
        End If
    End Sub

    Public Sub GenConditionsFile(ByRef MisTime As Single, _
                                 ByRef MisWeather As Integer, _
                                 ByRef MisCloud As Integer, _
                                 ByRef wind As Weather, _
                                    ByRef INI_Settings As INI_Class)
        Dim sb As New StringBuilder
        sb.AppendLine("Time=" & Format(MisTime, "0.0000"))
        sb.AppendLine("Weather=" & Format(MisWeather, "0"))
        sb.AppendLine("Cloud=" & Format(MisCloud, "0"))
        sb.AppendLine("WindVelocity=" & Format(wind.Velocity, "0"))
        sb.AppendLine("WindDirection=" & Format(wind.Direction, "0"))
        sb.AppendLine("WindTop=" & Format(wind.Top, "0"))
        sb.AppendLine("WindTurbulence=" & Format(wind.Turbulence, "0"))
        sb.AppendLine("WindGust=" & Format(wind.Gust, "0"))
        Using outfile As New StreamWriter(INI_Settings.sCampaign & "\conditions.dcg")
            outfile.Write(sb.ToString())
            outfile.Close()
        End Using
    End Sub

    Public Sub SetConditions(ByRef MisTime As Single, _
                                ByRef MisWeather As Integer, _
                                ByRef MisCloud As Integer, _
                                ByRef wind As Weather, _
                                ByRef MissSettings As Mission)
        With MissSettings
            'Time
            If .StartTime > 22 Then .StartTime = 22
            If .StartTime < 1 Then .StartTime = 1
            If .EndTime > 22 Then .EndTime = 22
            If .EndTime < .StartTime Then .EndTime = .StartTime
            MisTime = Int((Rnd() * (1 + .EndTime - .StartTime)) + .StartTime) - (1 / 6)
            'Weather
            If .BCloudType < 0 Then .BCloudType = 0
            If .BCloudType > 6 Then .BCloudType = 6
            If .WCloudType < .BCloudType Then .WCloudType = .BCloudType
            If .WCloudType > 6 Then .WCloudType = 6
            MisWeather = Int((Rnd() * (1 + .WCloudType - .BCloudType)) + .BCloudType)
            'Wind Settings
            wind.Direction = Int((Rnd() * (1 + .HWindDirection - .LWindDirection)) + .LWindDirection)
            wind.Velocity = Int((Rnd() * (1 + .HWindVelocity - .LWindVelocity)) + .LWindVelocity)
            wind.Top = Int((Rnd() * (1 + .HWindtop - .LWindTop)) + .LWindTop)
            wind.Gust = Int((Rnd() * (1 + .WWindGust - .BWindGust)) + .BWindGust)
            wind.Turbulence = Int((Rnd() * (1 + .WWindTurbulence - .BWindTurbulence)) + .BWindTurbulence)
            'CloudHeight
            MisCloud = Int((Rnd() * (1 + .HCloud - .LCloud)) + .LCloud)
        End With
    End Sub
    Public Sub Check_Suppression(ByRef MissSettings As Mission, _
                                    ByRef Locat() As Location)
        'Find if location is Suppressed
        For intCount = 1 To Locat.Length - 1
            With Locat(intCount)
                .Suppressed = 0
                .FuelLimit = MissSettings.MaxFuel
                If MissSettings.BaseSupp > 0 Then
                    For intCount2 = 1 To Locat.Length - 1
                        If MissSettings.BaseDist > _
                            (Math.Sqrt(((.X - Locat(intCount2).X) ^ 2) + ((.Y - Locat(intCount2).Y) ^ 2))) / 10 ^ 3 Then
                            If .Side <> Locat(intCount2).Side Then
                                If .Supply < MissSettings.BaseSupply Then .Suppressed = 1
                                If .Fuel < MissSettings.BaseFuel Then .FuelLimit = MissSettings.FuelLimit
                                Exit For
                            End If
                        End If
                    Next
                End If
            End With
        Next
    End Sub

    Public Sub PlaceArmorColumnEngaged(ByRef intChief As Integer, _
                                        ByRef ConvoyVeh(,) As String, _
                                        ByRef ConvoyInfo() As Convoy, _
                                        ByRef MissSettings As Mission, _
                                        ByRef Col() As Column, _
                                        ByRef Locat() As Location, _
                                        ByRef Road() As Waypoint, _
                                        ByRef Chief() As String, _
                                        ByRef ChiefMov() As String, _
                                        ByRef ChiefRd() As String, _
                                        ByRef RoadWp() As String, _
                                        ByRef INI_Settings As INI_Class, _
                                        ByRef CamSettings As Campaign)
        Dim intUnit As Integer
        Dim dbX As Double
        Dim dbY As Double
        Dim intHead As Integer
        Dim intRd As Integer
        Dim intDir As Integer
        Dim intRnd As Integer
        Dim strOutput As String
        With Col(intChief)
            If .iFrom = .iTo Then 'Tanks at a named location
                If INI_Settings.iMovingDF > 0 And _
                    ((.Side = 1 And Locat(.iFrom).RedRoad > 0) Or _
                     (.Side = 2 And Locat(.iFrom).BlueRoad > 0)) Then
                    PlaceTankAtLocationMoving(intChief, _
                                        Locat, _
                                        MissSettings, _
                                        Col, _
                                        Road, _
                                        ChiefMov, _
                                        ChiefRd, _
                                        RoadWp, _
                                        INI_Settings)
                Else
                    If .Side = 1 Then
                        dbX = Locat(.iFrom).AlliedX
                        dbY = Locat(.iFrom).AlliedY
                        intHead = Locat(.iFrom).AlliedH
                        MoveCoor(Locat(.iFrom).AlliedX, _
                                    Locat(.iFrom).AlliedY, _
                                    Locat(.iFrom).AlliedH, _
                                    INI_Settings.sngStaticSep * 5)
                    Else
                        dbX = Locat(.iFrom).AxisX
                        dbY = Locat(.iFrom).AxisY
                        intHead = Locat(.iFrom).AxisH
                        MoveCoor(Locat(.iFrom).AxisX, _
                                    Locat(.iFrom).AxisY, _
                                    Locat(.iFrom).AxisH, _
                                    INI_Settings.sngStaticSep * 5)
                    End If

                    intDir = -1
                    intRnd = Int(Rnd() * INI_Settings.sngStaticSep * 3)
                    MoveCoor(dbX, _
                            dbY, _
                            intHead + (90 * intDir), _
                            intRnd)

                    For intUnit = 1 To .Curr
                        MoveCoor(dbX, _
                                dbY, _
                                intHead + (90 * intDir), _
                                INI_Settings.sngStaticSep)
                        strOutput = "  " & .Ident & Format(intUnit - 1, "0") & _
                                    " " & ConvoyVeh(intUnit, .ConType) & _
                                    " " & Format(.Side, "0") & _
                                    " " & Format(dbX, "########.00") & _
                                    " " & Format(dbY, "########.00") & _
                                    " " & Format(intHead + 90, "##0.0")
                        If InStr(strOutput, ".artillery") > 0 Then
                            strOutput = strOutput & _
                                    Format(INI_Settings.sngTankDly, " 0.0") & " " & _
                                    Format(INI_Settings.sngTankRng, "0")
                        Else
                            strOutput = strOutput & " 0.0"
                        End If

                        ReDim Preserve Chief(Chief.Length)
                        Chief(Chief.Length - 1) = strOutput
                    Next
                End If
            Else
                'Column on Road
                For intRd = Road.Length - 1 To 1 Step -1
                    If (Road(intRd).iFrom = .iTo And _
                            Road(intRd).iTo = .iFrom) Or _
                            (Road(intRd).iFrom = .iFrom And _
                            Road(intRd).iTo = .iTo) Then
                        If .Side = 1 Then
                            dbX = Road(intRd).AlliedX
                            dbY = Road(intRd).AlliedY
                            intHead = Road(intRd).AlliedH
                        Else
                            dbX = Road(intRd).AxisX
                            dbY = Road(intRd).AxisY
                            intHead = Road(intRd).AxisH
                        End If
                        Exit For
                    End If
                Next
                If intRd > 1 Then 'Check that Road exists
                    If INI_Settings.iMovingDF > 0 Then 'Place moving objects
                        PlaceCarMoving(intChief, _
                                       intRd, _
                                       ConvoyInfo, _
                                       MissSettings, _
                                       Col, _
                                       Road, _
                                       ChiefMov, _
                                       ChiefRd, _
                                       RoadWp, _
                                       INI_Settings)
                    Else
                        If .Side = 1 Then
                            MoveCoor(Road(intRd).AlliedX, _
                                Road(intRd).AlliedY, _
                                Road(intRd).AlliedH, _
                                INI_Settings.sngStaticSep * 5)
                        Else
                            MoveCoor(Road(intRd).AxisX, _
                                Road(intRd).AxisY, _
                                Road(intRd).AxisH, _
                                INI_Settings.sngStaticSep * 5)
                        End If

                        intDir = -1
                        intRnd = Int(Rnd() * INI_Settings.sngStaticSep * 3)
                        MoveCoor(dbX, _
                            dbY, _
                            intHead + (90 * intDir), _
                            intRnd)
                        For intUnit = 1 To .Curr
                            MoveCoor(dbX, _
                                dbY, _
                                intHead + (90 * intDir), _
                                INI_Settings.sngStaticSep * 2)
                            strOutput = "  " & .Ident & Format(intUnit - 1, "0") & _
                                " " & ConvoyVeh(intUnit, .ConType) & _
                                " " & Format(.Side, "0") & _
                                " " & Format(dbX, "########.00") & _
                                " " & Format(dbY, "########.00") & _
                                " " & Format(intHead + 90, "##0.0")
                            If InStr(strOutput, ".artillery") > 0 Then
                                strOutput = strOutput & _
                                    Format(INI_Settings.sngTankDly, " 0.0") & " " & _
                                    Format(INI_Settings.sngTankRng, "0")
                            Else
                                strOutput = strOutput & " 0.0"
                            End If

                            ReDim Preserve Chief(Chief.Length)
                            Chief(Chief.Length - 1) = strOutput
                        Next
                    End If
                End If
            End If
        End With
    End Sub

    Public Sub RepairColumns(ByRef Col() As Column, _
                                ByRef Locat() As Location, _
                                ByRef INI_Settings As INI_Class)
        Dim iCol As Integer
        Dim iUnit As Integer
        If Col.Length < 2 Then Exit Sub
        If INI_Settings.intRebuildCol < 1 Then Exit Sub
        For iCol = 1 To Col.Length - 1
            With Col(iCol)
                If .Curr < .OrigSize And .iFrom > 0 Then
                    If .Side = Locat(.iFrom).Side Then
                        iUnit = Int(Locat(.iFrom).Supply / 10)
                        .Curr = .Curr + iUnit
                        If .Curr > .OrigSize Then .Curr = .OrigSize
                    End If
                End If
            End With
        Next
    End Sub
    Public Sub Find_Transports(ByRef Transport() As Carry, _
                                ByRef Col() As Column) 'Finds which units are carrying which units
        Dim i As Integer
        ReDim Transport(0)
        If Col.Length < 2 Then Exit Sub
        For i = 1 To Col.Length - 1
            If InStr(Col(i).sFrom, "_Chief") > 0 Then
                ReDim Preserve Transport(Transport.Length)
                With Transport(Transport.Length - 1)
                    .Main = Col(i).sFrom
                    .Secondary = Col(i).Ident
                End With
            End If
        Next
    End Sub
    Public Sub RepairTrains(ByRef Train() As Column, _
                                ByRef Locat() As Location, _
                                ByRef Station() As Location, _
                                ByRef INI_Settings As INI_Class)
        Dim iCol As Integer
        Dim iUnit As Integer
        If Train.Length < 2 Then Exit Sub
        If INI_Settings.intRebuildCol < 1 Then Exit Sub
        For iCol = 1 To Train.Length - 1
            With Train(iCol)
                If .Curr < .OrigSize Then
                    If .Side = Station(.iFrom).Side Then
                        iUnit = Int(Locat(Station(.iFrom).intRoad).Supply / 20)
                        .Curr = .Curr + iUnit
                        If .Curr > .OrigSize Then .Curr = .OrigSize
                    End If
                End If
            End With
        Next
    End Sub
    Public Sub RepairShips(ByRef Ship() As Column, _
                            ByRef Locat() As Location, _
                            ByRef Harbor() As Location, _
                            ByRef INI_Settings As INI_Class)
        Dim iCol As Integer
        Dim iUnit As Integer
        If Ship.Length < 2 Then Exit Sub
        If INI_Settings.intRebuildCol < 1 Then Exit Sub
        For iCol = 1 To Ship.Length - 1
            With Ship(iCol)
                If .Curr < .Size Then
                    If .Side = Harbor(.iFrom).Side Then
                        iUnit = Int(Locat(Harbor(.iFrom).intRoad).Supply / 40)
                        .Curr = .Curr + iUnit
                        If .Curr > .Size Then .Curr = .Size
                    End If
                End If
            End With
        Next
    End Sub
    Public Sub PlaceTankMoving(ByRef iChief As Integer, _
                                ByRef iRd As Integer, _
                                ByRef MissSettings As Mission, _
                                ByRef Col() As Column, _
                                ByRef Road() As Waypoint, _
                                ByRef ChiefMov() As String, _
                                ByRef ChiefRd() As String, _
                                ByRef RoadWp() As String, _
                                ByRef INI_Settings As INI_Class)
        Dim i As Integer
        With Col(iChief)
            'Add Moving Chief
            ReDim Preserve ChiefMov(ChiefMov.Length)
            ChiefMov(ChiefMov.Length - 1) = "  " & .Ident & " " & .Unit & " " & Format(.Side, "0")
            'Add Road Name

            ReDim Preserve ChiefRd(ChiefRd.Length)
            ChiefRd(ChiefRd.Length - 1) = "[" & .Ident & "_Road]"
            'Find Road Direction
            If .iFrom = Road(iRd).iFrom Then
                'First WP
                Road(iRd).FrmSpn = Road(iRd).Start + INI_Settings.ColSpawn + 3 - Road(iRd).AxisSP
                Road(iRd).FrmStp = Road(iRd).iEnd - 3 - Road(iRd).AxisSP

                ReDim Preserve ChiefRd(ChiefRd.Length)
                ChiefRd(ChiefRd.Length - 1) = "  " & RoadWp(Road(iRd).FrmSpn) & _
                                    Format(INI_Settings.ColDelay * Road(iRd).AxisSP, " 0") & _
                                    " 2 2.00"
                'Rest of WP's
                For i = Road(iRd).FrmSpn + 1 To Road(iRd).FrmStp - 1 Step 1

                    ReDim Preserve ChiefRd(ChiefRd.Length)
                    ChiefRd(ChiefRd.Length - 1) = "  " & RoadWp(i) & " 0 2 2.00"
                Next

                ReDim Preserve ChiefRd(ChiefRd.Length)
                ChiefRd(ChiefRd.Length - 1) = "  " & RoadWp(Road(iRd).FrmStp)
                Road(iRd).AxisSP = Road(iRd).AxisSP + 1
            Else
                'First WP
                Road(iRd).ToSpn = Road(iRd).iEnd - INI_Settings.ColSpawn - 3 + Road(iRd).AlliedSP
                Road(iRd).ToStp = Road(iRd).Start + 3 + Road(iRd).AlliedSP

                ReDim Preserve ChiefRd(ChiefRd.Length)
                'Rest of WP's
                ChiefRd(ChiefRd.Length - 1) = "  " & RoadWp(Road(iRd).ToSpn) & _
                                    Format(INI_Settings.ColDelay * Road(iRd).AlliedSP, " 0") & _
                                    " 2 2.00"
                For i = Road(iRd).ToSpn - 1 To Road(iRd).ToStp + 1 Step -1

                    ReDim Preserve ChiefRd(ChiefRd.Length)
                    ChiefRd(ChiefRd.Length - 1) = "  " & RoadWp(i) & " 0 2 2.00"
                Next

                ReDim Preserve ChiefRd(ChiefRd.Length)
                ChiefRd(ChiefRd.Length - 1) = "  " & RoadWp(Road(iRd).ToStp)
                Road(iRd).AlliedSP = Road(iRd).AlliedSP + 1
            End If
        End With
    End Sub
    Public Sub PlaceTankAtLocationMoving(ByRef iChief As Integer, _
                                ByRef Locat() As Location, _
                                ByRef MissSettings As Mission, _
                                ByRef Col() As Column, _
                                ByRef Road() As Waypoint, _
                                ByRef ChiefMov() As String, _
                                ByRef ChiefRd() As String, _
                                ByRef RoadWp() As String, _
                                ByRef INI_Settings As INI_Class)
        'Places moving units at a location when they are engaged
        Dim i As Integer
        Dim iRd As Int64
        Dim sVehicle As String
        With Col(iChief)
            'Add Moving Chief

            ReDim Preserve ChiefMov(ChiefMov.Length)
            ChiefMov(ChiefMov.Length - 1) = "  " & .Ident & " " & .Unit & " " & Format(.Side, "0")
            If .ConType > 0 Then
                If .MultUnit > 0 Then
                    sVehicle = " Vehicles." & Format(.Curr, "0") & "-"
                    ChiefMov(ChiefMov.Length - 1) = Replace(ChiefMov(ChiefMov.Length - 1), " Vehicles.", sVehicle)
                End If
            End If
            'Add Road Name

            ReDim Preserve ChiefRd(ChiefRd.Length)
            ChiefRd(ChiefRd.Length - 1) = "[" & .Ident & "_Road]"
            If .Side = 1 Then
                iRd = Locat(.iFrom).RedRoad

                For i = Locat(.iFrom).RedWp + Locat(.iFrom).RedCol To _
                            Road(iRd).Start + Locat(.iFrom).RedCol + 1 Step -1
                    ReDim Preserve ChiefRd(ChiefRd.Length)
                    ChiefRd(ChiefRd.Length - 1) = "  " & RoadWp(i) & " 0 2 2.00"
                Next
                ReDim Preserve ChiefRd(ChiefRd.Length)
                ChiefRd(ChiefRd.Length - 1) = "  " & RoadWp(Road(iRd).Start + Locat(.iFrom).RedCol)
                Locat(.iFrom).RedCol += 1
            Else

                iRd = Locat(.iFrom).BlueRoad
                For i = Locat(.iFrom).BlueWP - Locat(.iFrom).BlueCol To _
                            Road(iRd).iEnd - Locat(.iFrom).BlueCol - 1 Step 1
                    ReDim Preserve ChiefRd(ChiefRd.Length)
                    ChiefRd(ChiefRd.Length - 1) = "  " & RoadWp(i) & " 0 2 2.00"
                Next
                ReDim Preserve ChiefRd(ChiefRd.Length)
                ChiefRd(ChiefRd.Length - 1) = "  " & RoadWp(Road(iRd).iEnd - Locat(.iFrom).BlueCol)
                Locat(.iFrom).BlueCol += 1
            End If

        End With
    End Sub
    Public Sub PlaceInfantryAtLocationMoving(ByRef iChief As Integer, _
                                ByRef Locat() As Location, _
                                ByRef MissSettings As Mission, _
                                ByRef Infantry() As Column, _
                                ByRef Trail() As Waypoint, _
                                ByRef ChiefMov() As String, _
                                ByRef ChiefRd() As String, _
                                ByRef TrailWp() As String, _
                                ByRef INI_Settings As INI_Class)
        'Places moving units at a location when they are engaged
        Dim i As Integer
        Dim iRd As Int64
        With Infantry(iChief)
            'Add Moving Chief
            ReDim Preserve ChiefMov(ChiefMov.Length)
            ChiefMov(ChiefMov.Length - 1) = "  " & .Ident & " " & .Unit & " " & Format(.Side, "0")
            'Add trail Name

            ReDim Preserve ChiefRd(ChiefRd.Length)
            ChiefRd(ChiefRd.Length - 1) = "[" & .Ident & "_Road]"
            If .Side = 1 Then
                iRd = Locat(.iFrom).RedRoad

                For i = Locat(.iFrom).RedWp + Locat(.iFrom).RedCol To _
                            Trail(iRd).Start + 1 Step -1
                    ReDim Preserve ChiefRd(ChiefRd.Length)
                    ChiefRd(ChiefRd.Length - 1) = "  " & TrailWp(i) & " 0 2 2.00"
                Next
                ReDim Preserve ChiefRd(ChiefRd.Length)
                ChiefRd(ChiefRd.Length - 1) = "  " & TrailWp(Trail(iRd).Start)
                Locat(.iFrom).RedCol += 1
            Else
                iRd = Locat(.iFrom).BlueRoad

                For i = Locat(.iFrom).BlueWP - Locat(.iFrom).BlueCol To _
                            Trail(iRd).iEnd - 1 Step 1
                    ReDim Preserve ChiefRd(ChiefRd.Length)
                    ChiefRd(ChiefRd.Length - 1) = "  " & TrailWp(i) & " 0 2 2.00"
                Next
                ReDim Preserve ChiefRd(ChiefRd.Length)
                ChiefRd(ChiefRd.Length - 1) = "  " & TrailWp(Trail(iRd).iEnd)
                Locat(.iFrom).BlueCol += 1
            End If

        End With
    End Sub
    Public Sub PlaceTrainMov(ByRef iChief As Integer, _
                                ByRef iRd As Integer, _
                                ByRef MissSettings As Mission, _
                                ByRef Train() As Column, _
                                ByRef Rail() As Waypoint, _
                                ByRef ChiefMov() As String, _
                                ByRef ChiefRd() As String, _
                                ByRef RailWP() As String, _
                                ByRef INI_Settings As INI_Class)
        Dim i As Integer
        With Train(iChief)
            ReDim Preserve ChiefMov(ChiefMov.Length)
            ChiefMov(ChiefMov.Length - 1) = "  " & .Ident & " " & _
                                        .Unit & " " & _
                                        Format(.Side, "0")

            ReDim Preserve ChiefRd(ChiefRd.Length)
            ChiefRd(ChiefRd.Length - 1) = "[" & .Ident & "_Road]"
            If .iFrom = Rail(iRd).iFrom Then
                'First WP

                ReDim Preserve ChiefRd(ChiefRd.Length)
                ChiefRd(ChiefRd.Length - 1) = "  " & RailWP(Rail(iRd).FrmSpn) & _
                                        Format(INI_Settings.TrainDelay * Rail(iRd).AxisSP, " 0") & _
                                        " 2 2.00"
                'Remaining WPs
                For i = Rail(iRd).FrmSpn + 1 To Rail(iRd).ToStp - 1 Step 1

                    ReDim Preserve ChiefRd(ChiefRd.Length)
                    ChiefRd(ChiefRd.Length - 1) = "  " & RailWP(i) & " 0 2 2.00"
                Next
                'Last WP

                ReDim Preserve ChiefRd(ChiefRd.Length)
                ChiefRd(ChiefRd.Length - 1) = "  " & RailWP(Rail(iRd).ToStp)
                Rail(iRd).FrmSpn = Rail(iRd).FrmSpn + 1
                Rail(iRd).ToStp = Rail(iRd).ToStp + 1
                Rail(iRd).AxisSP = Rail(iRd).AxisSP + 1
            Else
                'First WP

                ReDim Preserve ChiefRd(ChiefRd.Length)
                ChiefRd(ChiefRd.Length - 1) = "  " & RailWP(Rail(iRd).ToSpn) & _
                                        Format(INI_Settings.TrainDelay * Rail(iRd).AlliedSP, " 0") & _
                                        " 2 2.00"
                'Remaining WPs
                For i = Rail(iRd).ToSpn - 1 To Rail(iRd).FrmStp + 1 Step -1

                    ReDim Preserve ChiefRd(ChiefRd.Length)
                    ChiefRd(ChiefRd.Length - 1) = "  " & RailWP(i) & " 0 2 2.00"
                Next
                'Last WP

                ReDim Preserve ChiefRd(ChiefRd.Length)
                ChiefRd(ChiefRd.Length - 1) = "  " & RailWP(i)
                Rail(iRd).ToSpn = Rail(iRd).ToSpn - 1
                Rail(iRd).FrmStp = Rail(iRd).FrmStp - 1
                Rail(iRd).AlliedSP = Rail(iRd).AlliedSP + 1
            End If
        End With
    End Sub
    Public Sub PlaceCarMoving(ByRef iChief As Integer, _
                                ByRef iRd As Integer, _
                                ByRef convoyinfo() As Convoy, _
                                ByRef MissSettings As Mission, _
                                ByRef Col() As Column, _
                                ByRef Road() As Waypoint, _
                                ByRef ChiefMov() As String, _
                                ByRef ChiefRd() As String, _
                                ByRef RoadWp() As String, _
                                ByRef INI_Settings As INI_Class)
        Dim i As Integer
        Dim sVehicle As String
        Dim iWp As Integer
        With Col(iChief)
            'Add Moving Chiefs

            ReDim Preserve ChiefMov(ChiefMov.Length)
            ChiefMov(ChiefMov.Length - 1) = "  " & .Ident & " " & _
                                        .Unit & " " & _
                                        Format(.Side, "0")
            If .ConType > 0 Then
                If convoyinfo(.ConType).MultUnits > 0 Then
                    sVehicle = " Vehicles." & Format(.Curr, "0") & "-"
                    ChiefMov(ChiefMov.Length - 1) = Replace(ChiefMov(ChiefMov.Length - 1), " Vehicles.", sVehicle)
                End If
            End If
            'Add Road Name

            ReDim Preserve ChiefRd(ChiefRd.Length)
            ChiefRd(ChiefRd.Length - 1) = "[" & .Ident & "_Road]"
            iWp = Int(Rnd() * 5)
            'Find Road Direction
            If .iFrom = Road(iRd).iFrom Then
                'First WP
                Road(iRd).FrmSpn = Road(iRd).Start + INI_Settings.ColSpawn + 3 - Road(iRd).AxisSP
                Road(iRd).FrmStp = Road(iRd).iEnd - 3 - Road(iRd).AxisSP

                ReDim Preserve ChiefRd(ChiefRd.Length)
                ChiefRd(ChiefRd.Length - 1) = "  " & RoadWp(Road(iRd).FrmSpn) & _
                                    Format(INI_Settings.ColDelay * (10 + Road(iRd).AxisSP), " 0") & _
                                    " 2 2.00"
                'Rest of WP's
                For i = Road(iRd).FrmSpn + 1 To Road(iRd).FrmStp - 1 Step 1

                    ReDim Preserve ChiefRd(ChiefRd.Length)
                    ChiefRd(ChiefRd.Length - 1) = "  " & RoadWp(i) & " 0 2 2.00"
                Next

                ReDim Preserve ChiefRd(ChiefRd.Length)
                ChiefRd(ChiefRd.Length - 1) = "  " & RoadWp(Road(iRd).FrmStp)
                Road(iRd).AxisSP = Road(iRd).AxisSP + 1
            Else
                'First WP
                Road(iRd).ToSpn = Road(iRd).iEnd - INI_Settings.ColSpawn - 3 + Road(iRd).AlliedSP
                Road(iRd).ToStp = Road(iRd).Start + 3 + Road(iRd).AlliedSP

                ReDim Preserve ChiefRd(ChiefRd.Length)
                ChiefRd(ChiefRd.Length - 1) = "  " & RoadWp(Road(iRd).ToSpn) & _
                                    Format(INI_Settings.ColDelay * (10 + Road(iRd).AlliedSP), " 0") & _
                                    " 2 2.00"
                'Rest of WP's
                For i = Road(iRd).ToSpn - 1 To Road(iRd).ToStp + 1 Step -1

                    ReDim Preserve ChiefRd(ChiefRd.Length)
                    ChiefRd(ChiefRd.Length - 1) = "  " & RoadWp(i) & " 0 2 2.00"
                Next

                ReDim Preserve ChiefRd(ChiefRd.Length)
                ChiefRd(ChiefRd.Length - 1) = "  " & RoadWp(Road(iRd).ToStp)
                Road(iRd).AlliedSP = Road(iRd).AlliedSP + 1
            End If
        End With
    End Sub
    Public Sub PlaceShipConvoyMoving(ByRef iChief As Integer, _
                                        ByRef iRd As Integer, _
                                        ByRef BornPlace() As BornPlaceClass, _
                                        ByRef ConvoyVeh(,) As String, _
                                        ByRef MissSettings As Mission, _
                                        ByRef Ship() As Column, _
                                        ByRef ShipRoute() As Waypoint, _
                                        ByRef ChiefMov() As String, _
                                        ByRef ChiefRd() As String, _
                                        ByRef SeaWP() As WP, _
                                        ByRef INI_Settings As INI_Class, _
                                        ByRef iShipOffSet As Int16)
        Dim i As Integer
        Dim iSize As Integer
        Dim dX As Double
        Dim dY As Double
        Dim iH As Integer
        Dim iBP As Integer
        With Ship(iChief)
            If .iFrom = ShipRoute(iRd).iFrom Then
                dX = ShipRoute(iRd).AxisX
                dY = ShipRoute(iRd).AxisY
                iH = ShipRoute(iRd).AxisH
                MoveCoor(ShipRoute(iRd).AxisX, _
                    ShipRoute(iRd).AxisY, _
                    ShipRoute(iRd).AxisH, 2 * INI_Settings.ShipSep)
                i = iShipOffSet
                If i > 0 Then
                    i = 90
                    iShipOffSet = -1
                Else
                    i = 270
                    iShipOffSet = 1
                End If
                MoveCoor(ShipRoute(iRd).AxisX, _
                        ShipRoute(iRd).AxisY, _
                        ShipRoute(iRd).AxisH + i, INI_Settings.ShipSep)
            Else
                dX = ShipRoute(iRd).AlliedX
                dY = ShipRoute(iRd).AlliedY
                iH = ShipRoute(iRd).AlliedH
                MoveCoor(ShipRoute(iRd).AlliedX, _
                    ShipRoute(iRd).AlliedY, _
                    ShipRoute(iRd).AlliedH, 2 * INI_Settings.ShipSep)
                i = iShipOffSet
                If i > 0 Then
                    i = 90
                    iShipOffSet = -1
                Else
                    i = 270
                    iShipOffSet = 1
                End If
                MoveCoor(ShipRoute(iRd).AlliedX, _
                        ShipRoute(iRd).AlliedY, _
                        ShipRoute(iRd).AlliedH + i, INI_Settings.ShipSep)
            End If
            'Add Moving Chiefs
            For iSize = 1 To .Curr

                ReDim Preserve ChiefMov(ChiefMov.Length)
                ChiefMov(ChiefMov.Length - 1) = "  " & .Ident & Format(iSize - 1, "0") & " " & _
                                        ConvoyVeh(iSize, .ConType) & " " & _
                                        Format(.Side, "0 ") & .ROF

                If InStr(.Unit, "Ships.") > 0 Then ChiefMov(ChiefMov.Length - 1) = Replace(ChiefMov(ChiefMov.Length - 1), "ships.Ship$", "Ships.")
                If InStr(.Unit, "ShipPack.") > 0 Then ChiefMov(ChiefMov.Length - 1) = Replace(ChiefMov(ChiefMov.Length - 1), "ships.Ship$", "ShipPack.")
                'Add Road Name

                ReDim Preserve ChiefRd(ChiefRd.Length)
                ChiefRd(ChiefRd.Length - 1) = "[" & .Ident & Format(iSize - 1, "0") & "_Road]"
                'Find Road Direction
                If .iFrom = ShipRoute(iRd).iFrom Then
                    dX = ShipRoute(iRd).AxisX
                    dY = ShipRoute(iRd).AxisY
                    iH = ShipRoute(iRd).AxisH
                    MoveCoor(ShipRoute(iRd).AxisX, _
                        ShipRoute(iRd).AxisY, _
                        ShipRoute(iRd).AxisH, INI_Settings.ShipSep)
                    i = iShipOffSet
                    If i > 0 Then
                        i = 90
                        iShipOffSet = -1
                    Else
                        i = 270
                        iShipOffSet = 1
                    End If
                    MoveCoor(ShipRoute(iRd).AxisX, _
                            ShipRoute(iRd).AxisY, _
                            ShipRoute(iRd).AxisH + i, INI_Settings.ShipSep)
                Else
                    dX = ShipRoute(iRd).AlliedX
                    dY = ShipRoute(iRd).AlliedY
                    iH = ShipRoute(iRd).AlliedH
                    MoveCoor(ShipRoute(iRd).AlliedX, _
                        ShipRoute(iRd).AlliedY, _
                        ShipRoute(iRd).AlliedH, INI_Settings.ShipSep)
                    i = iShipOffSet
                    If i > 0 Then
                        i = 90
                        iShipOffSet = -1
                    Else
                        i = 270
                        iShipOffSet = 1
                    End If
                    MoveCoor(ShipRoute(iRd).AlliedX, _
                            ShipRoute(iRd).AlliedY, _
                            ShipRoute(iRd).AlliedH + i, INI_Settings.ShipSep)
                End If


                If .iFrom = ShipRoute(iRd).iFrom Then
                    'First WP

                    ReDim Preserve ChiefRd(ChiefRd.Length)
                    i = ShipRoute(iRd).Start + 2
                    ChiefRd(ChiefRd.Length - 1) = "  " & Format(SeaWP(i).X + dX, "0.00") & " " & _
                                        Format(SeaWP(i).Y + dY, "0.00") & " 120.00 0 2" & _
                                        Format(INI_Settings.ShipSpeed, " 0.00")
                    If .Carrier > 0 And .Carrier = iSize Then
                        For iBP = 1 To BornPlace.Length - 1
                            If BornPlace(iBP).Loc = .Ident Then
                                BornPlace(iBP).Active = True
                                BornPlace(iBP).X = SeaWP(i).X + dX
                                BornPlace(iBP).Y = SeaWP(i).Y + dY
                            End If
                        Next
                    End If
                    'Remaining WPs
                    For i = ShipRoute(iRd).Start + 3 To ShipRoute(iRd).iEnd - 3 - 1 Step 1

                        ReDim Preserve ChiefRd(ChiefRd.Length)
                        ChiefRd(ChiefRd.Length - 1) = "  " & Format(SeaWP(i).X + dX, "0.00") & " " & _
                                                Format(SeaWP(i).Y + dY, "0.00") & " " & _
                                                Format(SeaWP(i).H, "0.00") & " 0 2" & _
                                        Format(INI_Settings.ShipSpeed, " 0.00")
                    Next
                    ChiefRd(ChiefRd.Length - 1) = "  " & Format(SeaWP(ShipRoute(iRd).iEnd - 3).X + dX, "0.00") & " " & _
                                                Format(SeaWP(ShipRoute(iRd).iEnd - 3).Y + dY, "0.00") & " " & _
                                                Format(SeaWP(ShipRoute(iRd).iEnd - 3).H, "0.00")
                Else
                    'First WP

                    ReDim Preserve ChiefRd(ChiefRd.Length)
                    i = ShipRoute(iRd).iEnd - 2
                    ChiefRd(ChiefRd.Length - 1) = "  " & Format(SeaWP(i).X + dX, "0.00") & " " & _
                                        Format(SeaWP(i).Y + dY, "0.00") & " 120.00 0 2" & _
                                        Format(INI_Settings.ShipSpeed, " 0.00")
                    If .Carrier > 0 And .Carrier = iSize Then
                        For iBP = 1 To BornPlace.Length - 1
                            If BornPlace(iBP).Loc = .Ident Then
                                BornPlace(iBP).Active = True
                                BornPlace(iBP).X = SeaWP(i).X + dX
                                BornPlace(iBP).Y = SeaWP(i).Y + dY
                            End If
                        Next
                    End If
                    'Remaining WPs
                    For i = ShipRoute(iRd).iEnd - 3 To ShipRoute(iRd).Start + 1 Step -1

                        ReDim Preserve ChiefRd(ChiefRd.Length)
                        ChiefRd(ChiefRd.Length - 1) = "  " & Format(SeaWP(i).X + dX, "0.00") & " " & _
                                                Format(SeaWP(i).Y + dY, "0.00") & " " & _
                                                Format(SeaWP(i).H, "0.00") & " 0 2" & _
                                        Format(INI_Settings.ShipSpeed, " 0.00")
                    Next
                    ChiefRd(ChiefRd.Length - 1) = "  " & Format(SeaWP(ShipRoute(iRd).Start).X + dX, "0.00") & " " & _
                                                Format(SeaWP(ShipRoute(iRd).Start).Y + dY, "0.00") & " " & _
                                                Format(SeaWP(ShipRoute(iRd).Start).H, "0.00")
                End If
            Next
        End With
    End Sub
    Public Sub PlaceShipMoving(ByRef iChief As Integer, _
                                ByRef iRd As Integer, _
                                ByRef MissSettings As Mission, _
                                ByRef Ship() As Column, _
                                ByRef ShipRoute() As Waypoint, _
                                ByRef ChiefMov() As String, _
                                ByRef ChiefRd() As String, _
                                ByRef SeaWP() As WP, _
                                ByRef INI_Settings As INI_Class, _
                                ByRef iShipOffset As Int16)
        Dim i As Integer
        Dim dX As Double
        Dim dY As Double
        Dim iH As Integer
        Dim iWP As Integer
        With Ship(iChief)
            'Move Ship Start Point
            If .iFrom = ShipRoute(iRd).iFrom Then
                dX = ShipRoute(iRd).AxisX
                dY = ShipRoute(iRd).AxisY
                iH = ShipRoute(iRd).AxisH
                MoveCoor(ShipRoute(iRd).AxisX, _
                    ShipRoute(iRd).AxisY, _
                    ShipRoute(iRd).AxisH, 2 * INI_Settings.ShipSep)
                i = iShipOffset
                If i > 0 Then
                    i = 90
                    iShipOffset = -1
                Else
                    i = 270
                    iShipOffset = 1
                End If
                MoveCoor(ShipRoute(iRd).AxisX, _
                        ShipRoute(iRd).AxisY, _
                        ShipRoute(iRd).AxisH + i, INI_Settings.ShipSep)
            Else
                dX = ShipRoute(iRd).AlliedX
                dY = ShipRoute(iRd).AlliedY
                iH = ShipRoute(iRd).AlliedH
                MoveCoor(ShipRoute(iRd).AlliedX, _
                    ShipRoute(iRd).AlliedY, _
                    ShipRoute(iRd).AlliedH, 2 * INI_Settings.ShipSep)
                i = iShipOffset
                If i > 0 Then
                    i = 90
                    iShipOffset = -1
                Else
                    i = 270
                    iShipOffset = 1
                End If
                MoveCoor(ShipRoute(iRd).AlliedX, _
                        ShipRoute(iRd).AlliedY, _
                        ShipRoute(iRd).AlliedH + i, INI_Settings.ShipSep)
            End If

            'Add Moving Chiefs

            ReDim Preserve ChiefMov(ChiefMov.Length)
            ChiefMov(ChiefMov.Length - 1) = "  " & .Ident & " " & _
                                        .Unit & " " & _
                                        Format(.Side, "0 ") & .ROF
            ChiefMov(ChiefMov.Length - 1) = Replace(ChiefMov(ChiefMov.Length - 1), "ships.Ship$", "Ships.")
            'Add Road Name

            ReDim Preserve ChiefRd(ChiefRd.Length)
            ChiefRd(ChiefRd.Length - 1) = "[" & .Ident & "_Road]"
            iWP = Int(Rnd() * 5)
            'Find Road Direction
            If .iFrom = ShipRoute(iRd).iFrom Then
                'First WP

                ReDim Preserve ChiefRd(ChiefRd.Length)
                i = ShipRoute(iRd).Start + 2
                ChiefRd(ChiefRd.Length - 1) = "  " & Format(SeaWP(i).X + dX, "0.00") & " " & _
                                        Format(SeaWP(i).Y + dY, "0.00") & " " & _
                                        Format(SeaWP(i).H, "0.00") & " 0 2" & _
                                        Format(INI_Settings.ShipSpeed, " 0.00")
                'Rest of WP's
                For i = ShipRoute(iRd).Start + 3 To ShipRoute(iRd).iEnd - 1 Step 1

                    ReDim Preserve ChiefRd(ChiefRd.Length)
                    ChiefRd(ChiefRd.Length - 1) = "  " & Format(SeaWP(i).X + dX, "0.00") & " " & _
                                            Format(SeaWP(i).X + dX, "0.00") & " " & _
                                            Format(SeaWP(i).H, "0.00") & " 0 2" & _
                                            Format(INI_Settings.ShipSpeed, " 0.00")
                Next

                ReDim Preserve ChiefRd(ChiefRd.Length)
                ChiefRd(ChiefRd.Length - 1) = "  " & Format(SeaWP(ShipRoute(iRd).iEnd).X + dX, "0.00") & " " & _
                                            Format(SeaWP(ShipRoute(iRd).iEnd).X + dX, "0.00") & " " & _
                                            Format(SeaWP(ShipRoute(iRd).iEnd).H, "0.00")
            Else
                'First WP

                ReDim Preserve ChiefRd(ChiefRd.Length)
                i = ShipRoute(iRd).iEnd - 2
                ChiefRd(ChiefRd.Length - 1) = "  " & Format(SeaWP(i).X + dX, "0.00") & " " & _
                                        Format(SeaWP(i).Y + dY, "0.00") & " " & _
                                        Format(SeaWP(i).H, "0.00") & " 0 2" & _
                                        Format(INI_Settings.ShipSpeed, " 0.00")
                'Rest of WP's
                For i = ShipRoute(iRd).iEnd - 3 To ShipRoute(iRd).Start + 1 Step -1

                    ReDim Preserve ChiefRd(ChiefRd.Length)
                    ChiefRd(ChiefRd.Length - 1) = "  " & Format(SeaWP(i).X + dX, "0.00") & " " & _
                                            Format(SeaWP(i).X + dX, "0.00") & " " & _
                                            Format(SeaWP(i).H, "0.00") & " 0 2" & _
                                            Format(INI_Settings.ShipSpeed, " 0.00")
                Next

                ReDim Preserve ChiefRd(ChiefRd.Length)
                ChiefRd(ChiefRd.Length - 1) = "  " & Format(SeaWP(ShipRoute(iRd).Start).X + dX, "0.00") & " " & _
                                            Format(SeaWP(ShipRoute(iRd).Start).X + dX, "0.00") & " " & _
                                            Format(SeaWP(ShipRoute(iRd).Start).H, "0.00")
            End If
        End With
    End Sub
    Public Sub GenSC_INI(ByRef sMissFolder As String, _
                            ByRef MissSettings As Mission, _
                            ByRef Squad() As Squad_Type, _
                            ByRef INI_Settings As INI_Class) 'Generates the INI file for Server Commander
        Dim AC_INI(0) As SC_Aircraft
        Dim iAC_INI As Integer
        Dim i As Integer
        Dim iType As Integer
        Dim sb As New StringBuilder
        'Find AC Numbers
        For i = 1 To Squad.Length - 1
            If iAC_INI < 1 Then
                iAC_INI = 1
                ReDim AC_INI(1)
                AC_INI(iAC_INI).Type = Squad(i).DF
                AC_INI(iAC_INI).Count = Squad(i).Number
                AC_INI(iAC_INI).Side = Squad(i).Side
                AC_INI(iAC_INI).Weapons = Squad(i).Weapon
            Else
                For iType = iAC_INI To 1 Step -1
                    If AC_INI(iType).Type = Squad(i).DF Then Exit For
                Next
                If iType < 1 Then
                    iAC_INI = iAC_INI + 1
                    ReDim Preserve AC_INI(iAC_INI)
                    AC_INI(iAC_INI).Type = Squad(i).DF
                    AC_INI(iAC_INI).Count = Squad(i).Number
                    AC_INI(iAC_INI).Side = Squad(i).Side
                    AC_INI(iAC_INI).Weapons = Squad(i).Weapon
                Else
                    AC_INI(iType).Count = AC_INI(iType).Count + Squad(i).Number
                End If
            End If
        Next
        'Common Section
        sb.AppendLine("[Common]")
        sb.AppendLine("TimeLimit=" & Format(INI_Settings.MisLength, "0"))
        sb.AppendLine("CountStaticPlanes=1")
        'Red Aircraft Section
        sb.AppendLine("[PlanesArmy1]")
        For iType = 1 To iAC_INI
            If AC_INI(iType).Side = 1 Then
                sb.AppendLine(AC_INI(iType).Type & "=" & _
                                AC_INI(iType).Count)
                If Len(AC_INI(iType).Weapons) > 0 Then
                    sb.Append("," & Mid(AC_INI(iType).Weapons, 2, Len(AC_INI(iType).Weapons) - 2))
                End If
            End If
        Next
        'Blue Aircraft Section
        sb.AppendLine("[PlanesArmy2]")
        For iType = 1 To iAC_INI
            If AC_INI(iType).Side = 2 Then
                sb.AppendLine(AC_INI(iType).Type & "=" & _
                                AC_INI(iType).Count)
                If Len(AC_INI(iType).Weapons) > 0 Then
                    sb.Append("," & Mid(AC_INI(iType).Weapons, 2, Len(AC_INI(iType).Weapons) - 2))
                End If
            End If
        Next
        'Red Section
        sb.AppendLine("[Army1]")
        i = 0
        For iType = 1 To iAC_INI
            If AC_INI(iType).Side = 1 Then
                i = i + AC_INI(iType).Count
            End If
        Next
        sb.AppendLine("Planes=" & Format(i, "0"))
        sb.AppendLine("Pilots=" & Format(i, "0"))
        'Blue Section
        sb.AppendLine("[Army2]")
        i = 0
        For iType = 1 To iAC_INI
            If AC_INI(iType).Side = 2 Then
                i = i + AC_INI(iType).Count
            End If
        Next
        sb.AppendLine("Planes=" & Format(i, "0"))
        sb.AppendLine("Pilots=" & Format(i, "0"))
        'Using outfile As New StreamWriter(sMissFolder & "/dcgmission.ini")
        'outfile.Write(sb.ToString())
        'outfile.Close()
        'End Using
        FileOpen(1, sMissFolder & "/dcgmission.ini", OpenMode.Output, OpenAccess.Write, OpenShare.Shared)
        Print(1, sb.ToString)
        FileClose(1)
    End Sub
    Public Sub LoadAircraftFile(ByRef BornPlace() As BornPlaceClass, _
                                    ByRef MissSettings As Mission, _
                                    ByRef AC_New() As AC_Type, _
                                    ByRef Squad() As Squad_Type, _
                                    ByRef UseSquad As Integer, _
                                    ByRef INI_Settings As INI_Class, _
                                    ByRef bolError As Boolean, _
                                    ByRef strError As String)
        'Loads the AC available for the mission (used instead of Squads file)
        Dim sAircraftFile As String
        Dim sInput As String
        Dim sValue As String
        Dim iPos As Integer
        Dim i As Integer
        Dim iAC As Integer
        Dim iBP As Integer
        Dim filereader As IO.StreamReader
        sAircraftFile = INI_Settings.sCampaign & "\aircraft.dcg"
        If Dir(sAircraftFile) = "" Then
            bolError = True
            strError = "Cannot find column file!"
            Exit Sub
        End If
        If My.Computer.FileSystem.FileExists(sAircraftFile) Then
            filereader = My.Computer.FileSystem.OpenTextFileReader(sAircraftFile)
            Do Until filereader.EndOfStream
                sInput = filereader.ReadLine
                iPos = InStr(sInput, "aircraft=")
                If iPos > 0 And Len(sInput) > iPos Then
                    iPos = InStr(sInput, "=")
                    If Len(sInput) > iPos Then
                        sValue = Trim(Mid(sInput, iPos + 1))
                        ReDim Preserve AC_New(AC_New.Length)
                        AC_New(AC_New.Length - 1).Coop = sValue
                        AC_New(AC_New.Length - 1).DF = sValue
                        AC_New(AC_New.Length - 1).Type = 0
                        AC_New(AC_New.Length - 1).Weapons = "100 0 1"
                        AC_New(AC_New.Length - 1).Country = "null"
                    End If
                End If
                iPos = InStr(sInput, "dogfight=")
                If iPos > 0 And Len(sInput) > iPos Then
                    iPos = InStr(sInput, "=")
                    If Len(sInput) > iPos Then
                        sValue = Trim(Mid(sInput, iPos + 1))
                        AC_New(AC_New.Length - 1).DF = Trim(sValue)
                    End If
                End If
                iPos = InStr(sInput, "country=")
                If iPos > 0 And Len(sInput) > iPos Then
                    iPos = InStr(sInput, "=")
                    If Len(sInput) > iPos Then
                        sValue = Trim(Mid(sInput, iPos + 1))
                        AC_New(AC_New.Length - 1).Country = Trim(sValue)
                    End If
                End If
                'Types 0 = normal, 1 = carrier, 2 = seaplane
                iPos = InStr(sInput, "type=")
                If iPos > 0 And Len(sInput) > iPos Then
                    iPos = InStr(sInput, "=")
                    If Len(sInput) > iPos Then
                        sValue = Trim(Mid(sInput, iPos + 1))
                        AC_New(AC_New.Length - 1).Type = Int(Val(sValue))
                    Else
                        AC_New(AC_New.Length - 1).Type = 0
                    End If
                End If
                iPos = InStr(sInput, "weapons=")
                If iPos > 0 And Len(sInput) > iPos Then
                    iPos = InStr(sInput, "=")
                    If Len(sInput) > iPos Then
                        sValue = Trim(Mid(sInput, iPos + 1))
                        If Trim(sValue) = "" Then sValue = "100 0"
                        AC_New(AC_New.Length - 1).Weapons = Trim(sValue)
                    Else
                        AC_New(AC_New.Length - 1).Weapons = "100 0"
                    End If
                End If
                iPos = InStr(sInput, "max=")
                If iPos > 0 And Len(sInput) > iPos Then
                    iPos = InStr(sInput, "=")
                    If Len(sInput) > iPos Then
                        sValue = Trim(Mid(sInput, iPos + 1))
                        AC_New(AC_New.Length - 1).Max = Int(Val(sValue))
                    Else
                        AC_New(AC_New.Length - 1).Max = 0
                    End If
                End If
                iPos = InStr(sInput, "min=")
                If iPos > 0 And Len(sInput) > iPos Then
                    iPos = InStr(sInput, "=")
                    If Len(sInput) > iPos Then
                        sValue = Trim(Mid(sInput, iPos + 1))
                        AC_New(AC_New.Length - 1).Min = Int(Val(sValue))
                    Else
                        AC_New(AC_New.Length - 1).Min = 0
                    End If
                End If
                iPos = InStr(sInput, "resupply=")
                If iPos > 0 And Len(sInput) > iPos Then
                    iPos = InStr(sInput, "=")
                    If Len(sInput) > iPos Then
                        sValue = Trim(Mid(sInput, iPos + 1))
                        AC_New(AC_New.Length - 1).Resupply = Int(Val(sValue))
                    Else
                        AC_New(AC_New.Length - 1).Resupply = 0
                    End If
                End If
                iPos = InStr(sInput, "side=")
                If iPos > 0 And Len(sInput) > iPos Then
                    iPos = InStr(sInput, "=")
                    If Len(sInput) > iPos Then
                        sValue = Trim(Mid(sInput, iPos + 1))
                        AC_New(AC_New.Length - 1).Side = Int(Val(sValue))
                    End If
                End If
                iPos = InStr(sInput, "irfield=")
                If iPos > 0 And Len(sInput) > iPos And AC_New(AC_New.Length - 1).Type <> 6 Then
                    iPos = InStr(sInput, "=")
                    sValue = Trim(Left(sInput, iPos - 1))
                    For i = BornPlace.Length - 1 To 1 Step -1
                        If sValue = BornPlace(i).Loc And _
                            BornPlace(i).Side = AC_New(AC_New.Length - 1).Side Then
                            ReDim Preserve Squad(Squad.Length)
                            BornPlace(i).Active = True
                            Squad(Squad.Length - 1).Loc = sValue
                            Squad(Squad.Length - 1).iLoc = BornPlace(i).intLoc
                            Squad(Squad.Length - 1).Side = BornPlace(i).Side
                            Squad(Squad.Length - 1).Coop = AC_New(AC_New.Length - 1).Coop
                            Squad(Squad.Length - 1).DF = AC_New(AC_New.Length - 1).DF
                            Squad(Squad.Length - 1).Type = AC_New(AC_New.Length - 1).Type
                            Squad(Squad.Length - 1).WeaponsDF = AC_New(AC_New.Length - 1).Weapons
                            Squad(Squad.Length - 1).Country = AC_New(AC_New.Length - 1).Country
                            iPos = InStr(sInput, "=")
                            If Len(sInput) > iPos Then
                                sValue = Trim(Mid(sInput, iPos + 1))
                                Squad(Squad.Length - 1).Number = Int(Val(sValue))
                            Else
                                Squad(Squad.Length - 1).Number = 0
                            End If
                            Exit For
                        End If
                    Next
                End If
                iPos = InStr(sInput, "Chief=")
                If iPos > 0 And Len(sInput) > iPos And AC_New(AC_New.Length - 1).Type = 1 Then
                    iPos = InStr(sInput, "=")
                    sValue = Trim(Left(sInput, iPos - 1))
                    For i = BornPlace.Length - 1 To 1 Step -1
                        If sValue = BornPlace(i).Loc And _
                                    BornPlace(i).Side = AC_New(AC_New.Length - 1).Side Then
                            ReDim Preserve Squad(Squad.Length)
                            BornPlace(i).Active = True
                            Squad(Squad.Length - 1).Loc = sValue
                            Squad(Squad.Length - 1).iLoc = BornPlace(i).intLoc
                            Squad(Squad.Length - 1).Side = BornPlace(i).Side
                            Squad(Squad.Length - 1).Coop = AC_New(AC_New.Length - 1).Coop
                            Squad(Squad.Length - 1).DF = AC_New(AC_New.Length - 1).DF
                            Squad(Squad.Length - 1).Type = AC_New(AC_New.Length - 1).Type
                            Squad(Squad.Length - 1).WeaponsDF = AC_New(AC_New.Length - 1).Weapons
                            Squad(Squad.Length - 1).Country = AC_New(AC_New.Length - 1).Country
                            Squad(Squad.Length - 1).Suppressed = 0
                            Squad(Squad.Length - 1).FuelLimit = MissSettings.MaxFuel
                            iPos = InStr(sInput, "=")
                            If Len(sInput) > iPos Then
                                sValue = Trim(Mid(sInput, iPos + 1))
                                Squad(Squad.Length - 1).Number = Int(Val(sValue))
                            Else
                                Squad(Squad.Length - 1).Number = 0
                            End If
                            Exit For
                        End If
                    Next
                End If
                iPos = InStr(sInput, "_Seaplane_Base")
                If iPos > 0 And Len(sInput) > iPos And AC_New(AC_New.Length - 1).Type = 2 Then
                    iPos = InStr(sInput, "=")
                    sValue = Trim(Left(sInput, iPos - 1))
                    For i = BornPlace.Length - 1 To 1 Step -1
                        If sValue = BornPlace(i).Loc And _
                                    BornPlace(i).Side = AC_New(AC_New.Length - 1).Side Then
                            ReDim Preserve Squad(Squad.Length)
                            BornPlace(i).Active = True
                            Squad(Squad.Length - 1).Loc = sValue
                            Squad(Squad.Length - 1).iLoc = BornPlace(i).intLoc
                            Squad(Squad.Length - 1).Side = BornPlace(i).Side
                            Squad(Squad.Length - 1).Coop = AC_New(AC_New.Length - 1).Coop
                            Squad(Squad.Length - 1).DF = AC_New(AC_New.Length - 1).DF
                            Squad(Squad.Length - 1).Type = AC_New(AC_New.Length - 1).Type
                            Squad(Squad.Length - 1).WeaponsDF = AC_New(AC_New.Length - 1).Weapons
                            Squad(Squad.Length - 1).Country = AC_New(AC_New.Length - 1).Country
                            iPos = InStr(sInput, "=")
                            If Len(sInput) > iPos Then
                                sValue = Trim(Mid(sInput, iPos + 1))
                                Squad(Squad.Length - 1).Number = Int(Val(sValue))
                            Else
                                Squad(Squad.Length - 1).Number = 0
                            End If
                            Exit For
                        End If
                    Next
                End If
            Loop
            filereader.Close()
            For iBP = 1 To BornPlace.Length - 1
                For iAC = 1 To AC_New.Length - 1
                    If BornPlace(iBP).Side = AC_New(iAC).Side And _
                            ((BornPlace(iBP).Type = 0 And AC_New(iAC).Type <> 3) Or _
                            (BornPlace(iBP).Type = 1 And AC_New(iAC).Type = 1) Or _
                            (BornPlace(iBP).Type = 2 And AC_New(iAC).Type = 2)) Then
                        For i = Squad.Length - 1 To 1 Step -1
                            If Squad(i).Loc = BornPlace(iBP).Loc And _
                                    Squad(i).Coop = AC_New(iAC).Coop Then
                                Exit For
                            End If
                        Next
                        'If BornPlace(iBP).intLoc < 0 Then Stop
                        If i < 1 And (BornPlace(iBP).intLoc > 0 Or AC_New(iAC).Type = 9) Then
                            ReDim Preserve Squad(Squad.Length)
                            BornPlace(iBP).Active = True
                            Squad(Squad.Length - 1).Loc = BornPlace(iBP).Loc
                            Squad(Squad.Length - 1).iLoc = BornPlace(iBP).intLoc
                            Squad(Squad.Length - 1).Side = BornPlace(iBP).Side
                            Squad(Squad.Length - 1).WeaponsDF = AC_New(iAC).Weapons
                            Squad(Squad.Length - 1).Coop = AC_New(iAC).Coop
                            Squad(Squad.Length - 1).DF = AC_New(iAC).DF
                            Squad(Squad.Length - 1).Type = AC_New(iAC).Type
                            Squad(Squad.Length - 1).Number = 0
                            Squad(Squad.Length - 1).Country = AC_New(iAC).Country
                        End If
                    End If
                Next
            Next
        Else
            UseSquad = 1
            Exit Sub
        End If
    End Sub

    Public Sub GenAircraftFile(ByRef AC_New() As AC_Type, _
                                    ByRef Squad() As Squad_Type, _
                                    ByRef INI_Settings As INI_Class)
        Dim iAC As Integer
        Dim iBase As Integer
        Dim sb As New StringBuilder
        For iAC = 1 To AC_New.Length - 1
            With AC_New(iAC)
                sb.AppendLine("aircraft=" & .Coop)
                sb.AppendLine("dogfight=" & .DF)
                sb.AppendLine("country=" & .Country)
                sb.AppendLine("weapons=" & .Weapons)
                sb.AppendLine("type=" & .Type)
                sb.AppendLine("max=" & .Max)
                sb.AppendLine("min=" & .Min)
                sb.AppendLine("resupply=" & .Resupply)
                sb.AppendLine("side=" & .Side)
                For iBase = 1 To Squad.Length - 1
                    If Squad(iBase).Coop = .Coop Then
                        sb.AppendLine(Squad(iBase).Loc & "=" & Squad(iBase).Number)
                    End If
                Next
                sb.AppendLine()
            End With
        Next
        'Using outfile As New StreamWriter(INI_Settings.sCampaign & "\aircraft.dcg")
        'outfile.Write(sb.ToString())
        'outfile.Close()
        'End Using
        FileOpen(1, INI_Settings.sCampaign & "\aircraft.dcg", OpenMode.Output, OpenAccess.Write, OpenShare.Shared)
        Print(1, sb.ToString)
        FileClose(1)
    End Sub

    Public Sub Update_Squads(ByRef BornPlace() As BornPlaceClass, _
                                ByRef camsettings As Campaign, _
                                ByRef Locat() As Location, _
                                ByRef AC_New() As AC_Type, _
                                ByRef Squad() As Squad_Type)
        Dim iSquads As Integer
        Dim iAC As Integer
        Dim iBP As Integer
        For iSquads = 1 To Squad.Length - 1
            With Squad(iSquads)
                If .Loc = camsettings.RuHome Then
                    For iAC = 1 To AC_New.Length - 1
                        If AC_New(iAC).Coop = .Coop And AC_New(iAC).Side = 1 Then
                            .Number += AC_New(iAC).Resupply
                            If .Number > AC_New(iAC).Max Then .Number = AC_New(iAC).Max
                            If .Number < AC_New(iAC).Min Then .Number = AC_New(iAC).Min
                        End If
                    Next
                End If
                If .Loc = camsettings.DeHome Then
                    For iAC = 1 To AC_New.Length - 1
                        If AC_New(iAC).Coop = .Coop And AC_New(iAC).Side = 2 Then
                            .Number += AC_New(iAC).Resupply
                            If .Number > AC_New(iAC).Max Then .Number = AC_New(iAC).Max
                            If .Number < AC_New(iAC).Min Then .Number = AC_New(iAC).Min
                        End If
                    Next
                End If
                If .Loc = camsettings.RuSeaHome Then
                    For iAC = 1 To AC_New.Length - 1
                        If AC_New(iAC).Coop = .Coop And AC_New(iAC).Side = 1 Then
                            .Number += AC_New(iAC).Resupply
                            If .Number > AC_New(iAC).Max Then .Number = AC_New(iAC).Max
                            If .Number < AC_New(iAC).Min Then .Number = AC_New(iAC).Min
                        End If
                    Next
                End If
                If .Loc = camsettings.DeSeaHome Then
                    For iAC = 1 To AC_New.Length - 1
                        If AC_New(iAC).Coop = .Coop And AC_New(iAC).Side = 2 Then
                            .Number += AC_New(iAC).Resupply
                            If .Number > AC_New(iAC).Max Then .Number = AC_New(iAC).Max
                            If .Number < AC_New(iAC).Min Then .Number = AC_New(iAC).Min
                        End If
                    Next
                End If
                If .iLoc > 0 Then
                    If .Side <> Locat(.iLoc).Side Then
                        .Side = Locat(.iLoc).Side
                        .Coop = ""
                        .DF = ""
                        .Number = 0
                        For iBP = 1 To BornPlace.Length - 1
                            If BornPlace(iBP).intLoc = .iLoc Then BornPlace(iBP).Active = False
                        Next
                    End If
                End If
            End With
        Next
    End Sub
    Public Sub GenResults(ByRef BornPlace() As BornPlaceClass, _
                            ByRef MissSettings As Mission, _
                            ByRef Stat() As Stationary, _
                            ByRef Col() As Column, _
                            ByRef Ship() As Column, _
                            ByRef Train() As Column, _
                            ByRef Infantry() As Column, _
                            ByRef Locat() As Location, _
                            ByRef INI_Settings As INI_Class)
        Dim PilotRs(0) As Plt
        Dim totPilotRS As Integer
        Dim iPilot As Integer
        Dim sEventFile As String = ""
        Dim sEventDate As String = ""
        Dim sResultsFile As String = ""
        Dim sInput As String = ""
        Dim sPilot As String = ""
        Dim sAircraft As String = ""
        Dim sCoor As String = ""
        Dim sBase As String = ""
        Dim iBase As Integer
        Dim iBP As Integer
        Dim sType As String = ""
        Dim iPos As Integer
        Dim dX As Double
        Dim dY As Double
        Dim iH As Integer
        Dim sOutput As String = ""
        Dim datTime As Date
        Dim iSide As Integer
        Dim intStart As Integer
        Dim intPos As Integer
        Dim filereader As IO.StreamReader
        Dim sb As New StringBuilder
        Dim myDate As Date
        'This sub generates a "csv" results file for the mission
        sEventFile = INI_Settings.sServer & "\eventlog.dcg"
        If My.Computer.FileSystem.FileExists(sEventFile) Then
            filereader = My.Computer.FileSystem.OpenTextFileReader(sEventFile)
            Do Until filereader.EndOfStream
                sInput = filereader.ReadLine
                intStart = InStr(sInput, " Mission: ")
                If intStart > 0 Then 'Find Mission Date
                    intStart = InStr(sInput, "[")
                    intPos = InStr(sInput, "]") + 1
                    If intPos > intStart Then
                        sEventDate = Trim(Mid(sInput, intStart, intPos))
                    End If
                End If
                If sEventDate <> "" Then
                    'Inflight from an airbase
                    sPilot = ""
                    If InStr(sInput, " in flight at ") > 0 Then
                        Find_Pilot_Name(sInput, sPilot, sAircraft)

                        iPos = InStr(sInput, " in flight at ")
                        sCoor = Mid(sInput, iPos + 14)
                        FindCoor(sCoor, dX, dY, iH)
                        Find_Takeoff_Base(dX, _
                                          dY, _
                                          sBase, _
                                          iBase, _
                                          iBP, _
                                          BornPlace)
                        If iBase > 0 Then
                            totPilotRS = totPilotRS + 1
                            ReDim Preserve PilotRs(totPilotRS)
                            With PilotRs(totPilotRS)
                                .Name = sPilot
                                .Coop = sAircraft

                                .Side = Locat(iBase).Side
                                .Base = sBase
                                .iBase = iBase
                                .PltStatus = "cockpit"
                                .ACStatus = "inflight"
                                .BaseLanded = ""
                                .iBaseLanded = 0
                                .FriendAC = 0
                                .FriendGnd = 0
                                .SupplyMis = 0
                                .Infantry = 0
                                .Bridge = 0
                                .Plate = 0
                                .Time = FindTime(sInput)
                            End With
                        End If
                    End If
                    'In flight from a carrier
                    If InStr(sInput, "in flight from carrier") > 0 Then
                        Find_Pilot_Name(sInput, sPilot, sAircraft)
                        iPos = InStr(sInput, " carrier ")
                        sBase = Trim(Mid(sInput, iPos + 8))
                        iPos = InStr(sBase, " at ")
                        sBase = Trim(Left(sBase, iPos))
                        For iBase = Ship.Length - 1 To 1 Step -1
                            If Ship(iBase).Ident = sBase Then
                                iBase = iBase * -1
                                Exit For
                            End If
                        Next
                        For iBP = BornPlace.Length - 1 To 1 Step -1
                            If BornPlace(iBP).Loc = sBase Then Exit For
                        Next
                        totPilotRS = totPilotRS + 1
                        ReDim Preserve PilotRs(totPilotRS)
                        With PilotRs(totPilotRS)
                            .Name = sPilot
                            .Coop = sAircraft
                            .Side = Ship(iBase * -1).Side
                            .Base = sBase
                            .iBase = iBase
                            .PltStatus = "cockpit"
                            .ACStatus = "inflight"
                            .BaseLanded = ""
                            .iBaseLanded = 0
                            .FriendAC = 0
                            .FriendGnd = 0
                            .SupplyMis = 0
                            .Infantry = 0
                            .Time = FindTime(sInput)
                        End With
                    End If
                    If InStr(sInput, " has disconnected") > 0 Then
                        iPos = InStr(sInput, " has disconnected")
                        sPilot = Trim(Left(sInput, iPos))
                        iPos = InStr(sPilot, "] ")
                        If Len(sPilot) > iPos + 2 Then
                            sPilot = Trim(Mid(sPilot, iPos + 2))
                            For iPilot = totPilotRS To 1 Step -1
                                If sPilot = PilotRs(iPilot).Name Then
                                    If PilotRs(iPilot).ACStatus = "inflight" Then
                                        PilotRs(iPilot).ACStatus = "disconnected"
                                        datTime = FindTime(sInput)
                                        If datTime > PilotRs(iPilot).Time Then
                                            PilotRs(iPilot).InFlight = Math.Abs(DateDiff("n", datTime, PilotRs(iPilot).Time))
                                        End If
                                    End If
                                    Exit For
                                End If
                            Next
                        End If
                    End If


                    If InStr(sInput, " entered refly menu") > 0 Then
                        iPos = InStr(sInput, " entered refly menu")
                        sPilot = Trim(Left(sInput, iPos))
                        iPos = InStr(sPilot, "] ")
                        If Len(sPilot) > iPos + 2 Then
                            sPilot = Trim(Mid(sPilot, iPos + 2))
                            For iPilot = totPilotRS To 1 Step -1
                                If sPilot = PilotRs(iPilot).Name Then
                                    If PilotRs(iPilot).ACStatus = "inflight" Then
                                        PilotRs(iPilot).ACStatus = "disconnected"
                                        datTime = FindTime(sInput)
                                        If datTime > PilotRs(iPilot).Time Then
                                            PilotRs(iPilot).InFlight = Math.Abs(DateDiff(DateInterval.Minute, datTime, PilotRs(iPilot).Time))
                                        End If
                                    End If
                                    Exit For
                                End If
                            Next
                        End If
                    End If
                    'Landed at Airbase
                    If InStr(sInput, " landed at ") > 0 Then
                        Find_Pilot_Name(sInput, sPilot, sAircraft)
                        iPos = InStr(sInput, " at ")
                        sCoor = Mid(sInput, iPos + 4)
                        FindCoor(sCoor, dX, dY, iH)
                        Find_Base(dX, _
                                  dY, _
                                  sBase, _
                                  iBase, _
                                  iBP, _
                                  BornPlace, _
                                  INI_Settings)
                        For iPilot = totPilotRS To 1 Step -1
                            If sPilot = PilotRs(iPilot).Name Then
                                If PilotRs(iPilot).ACStatus = "inflight" Then
                                    datTime = FindTime(sInput)
                                    If datTime > PilotRs(iPilot).Time Then
                                        PilotRs(iPilot).InFlight = Math.Abs(DateDiff(DateInterval.Minute, datTime, PilotRs(iPilot).Time))
                                    End If
                                End If
                                PilotRs(iPilot).ACStatus = "landed"
                                PilotRs(iPilot).BaseLanded = sBase
                                PilotRs(iPilot).iBaseLanded = iBase
                                If PilotRs(iPilot).iBaseLanded <> PilotRs(iPilot).iBase Then
                                    PilotRs(iPilot).FerryMis = 1
                                End If
                                Exit For
                            End If
                        Next
                    End If
                    'Landed on Carrier
                    If InStr(sInput, "landed on carrier") > 0 Then
                        Find_Pilot_Name(sInput, sPilot, sAircraft)
                        iPos = InStr(sInput, " carrier ")
                        sBase = Trim(Mid(sInput, iPos + 8))
                        iPos = InStr(sBase, " at ")
                        sBase = Trim(Left(sBase, iPos))
                        For iBase = Ship.Length - 1 To 1 Step -1
                            If Ship(iBase).Ident = sBase Then
                                iBase = (iBase * -1)
                                Exit For
                            End If
                        Next
                        For iBP = BornPlace.Length - 1 To 1 Step -1
                            If BornPlace(iBP).Loc = sBase Then Exit For
                        Next
                        For iPilot = totPilotRS To 1 Step -1
                            If sPilot = PilotRs(iPilot).Name Then
                                If PilotRs(iPilot).ACStatus = "inflight" Then
                                    datTime = FindTime(sInput)
                                    If datTime > PilotRs(iPilot).Time Then
                                        PilotRs(iPilot).InFlight = Math.Abs(DateDiff(DateInterval.Minute, datTime, PilotRs(iPilot).Time))
                                    End If
                                End If
                                PilotRs(iPilot).ACStatus = "landed"
                                PilotRs(iPilot).BaseLanded = sBase
                                PilotRs(iPilot).iBaseLanded = iBase
                                If PilotRs(iPilot).iBaseLanded <> PilotRs(iPilot).iBase Then
                                    PilotRs(iPilot).FerryMis = 1
                                End If
                                Exit For
                            End If
                        Next
                    End If

                    If InStr(sInput, " crashed at ") > 0 Then
                        Find_Pilot_Name(sInput, sPilot, sAircraft)
                        For iPilot = totPilotRS To 1 Step -1
                            If sPilot = PilotRs(iPilot).Name Then
                                If PilotRs(iPilot).ACStatus = "inflight" Then
                                    datTime = FindTime(sInput)
                                    If datTime >= PilotRs(iPilot).Time Then
                                        PilotRs(iPilot).InFlight = Math.Abs(DateDiff(DateInterval.Minute, datTime, PilotRs(iPilot).Time))
                                    Else
                                        PilotRs(iPilot).InFlight = 0
                                    End If
                                End If
                                PilotRs(iPilot).ACStatus = "crashed"
                                Exit For
                            End If
                        Next
                    End If
                    'Supply Mission
                    If InStr(sInput, " supply mission at ") > 0 Or _
                            InStr(sInput, " supply drop at ") > 0 Then
                        Find_Pilot_Name(sInput, sPilot, sAircraft)
                        For iPilot = totPilotRS To 1 Step -1
                            If sPilot = PilotRs(iPilot).Name Then
                                PilotRs(iPilot).SupplyMis = 1
                                Exit For
                            End If
                        Next
                    End If
                    'Infantry  mission
                    If InStr(sInput, " dropped paratroops at ") > 0 Then
                        Find_Pilot_Name(sInput, sPilot, sAircraft)
                        For iPilot = totPilotRS To 1 Step -1
                            If sPilot = PilotRs(iPilot).Name Then
                                PilotRs(iPilot).Infantry = 1
                                Exit For
                            End If
                        Next
                    End If
                    'Infantry moved mission
                    If InStr(sInput, " moved ") > 0 Then
                        Find_Pilot_Name(sInput, sPilot, sAircraft)
                        For iPilot = totPilotRS To 1 Step -1
                            If sPilot = PilotRs(iPilot).Name Then
                                PilotRs(iPilot).Infantry = 1
                                Exit For
                            End If
                        Next
                    End If
                    If InStr(sInput, "(0) bailed out at ") > 0 Then
                        Find_Pilot_Name(sInput, sPilot, sAircraft)
                        For iPilot = totPilotRS To 1 Step -1
                            If sPilot = PilotRs(iPilot).Name Then
                                PilotRs(iPilot).PltStatus = "bailed"
                                Exit For
                            End If
                        Next
                    End If
                    If InStr(sInput, "captured at ") > 0 Then
                        Find_Pilot_Name(sInput, sPilot, sAircraft)
                        For iPilot = totPilotRS To 1 Step -1
                            If sPilot = PilotRs(iPilot).Name Then
                                PilotRs(iPilot).PltStatus = "captured"
                                Exit For
                            End If
                        Next
                    End If
                    If InStr(sInput, "(0) was killed ") > 0 Then
                        Find_Pilot_Name(sInput, sPilot, sAircraft)
                        For iPilot = totPilotRS To 1 Step -1
                            If sPilot = PilotRs(iPilot).Name Then
                                PilotRs(iPilot).PltStatus = "dead"
                                Exit For
                            End If
                        Next
                    End If
                    If InStr(sInput, " shot down by ") > 0 Then
                        Find_Pilot_Name(sInput, sPilot, sAircraft)
                        For iPilot = totPilotRS To 1 Step -1
                            If sPilot = PilotRs(iPilot).Name Then
                                If PilotRs(iPilot).ACStatus = "inflight" Then
                                    datTime = FindTime(sInput)
                                    If datTime > PilotRs(iPilot).Time Then
                                        PilotRs(iPilot).InFlight = Math.Abs(DateDiff(DateInterval.Minute, datTime, PilotRs(iPilot).Time))
                                    Else
                                        PilotRs(iPilot).InFlight = 0
                                    End If
                                End If
                                PilotRs(iPilot).ACStatus = "shot_down"
                                iSide = PilotRs(iPilot).Side
                                Exit For
                            End If
                        Next
                        'Find killer
                        Find_Pilot_By(sInput, sPilot)
                        If sPilot <> "" Then
                            For iPilot = totPilotRS To 1 Step -1
                                If sPilot = PilotRs(iPilot).Name Then
                                    If PilotRs(iPilot).Side <> iSide Then
                                        PilotRs(iPilot).Kills = PilotRs(iPilot).Kills + 1
                                    Else
                                        PilotRs(iPilot).FriendAC = PilotRs(iPilot).FriendAC + 1
                                    End If
                                    Exit For
                                End If
                            Next
                        End If
                    End If
                    If sInput.Contains("ExplosiveDamage") And _
                        sInput.Contains("_plate") Then
                        intStart = InStr(sInput, "]")
                        sPilot = Trim(Mid(sInput, intStart + 1))
                        Dim sArray() As String
                        sArray = sPilot.Split(" ")
                        For i = 0 To sInput.Length - 1
                            If i = 8 Then
                                sPilot = sArray(i)
                                If sPilot.Length > 2 Then
                                    sPilot = sPilot.Remove(sPilot.Length - 2)
                                    For iPilot = totPilotRS To 1 Step -1
                                        If sPilot = PilotRs(iPilot).Name Then
                                            PilotRs(iPilot).Plate += 1
                                            Exit For
                                        End If
                                    Next
                                End If
                            End If
                        Next
                    End If
                    If InStr(sInput, "destroyed by ") > 0 Then
                        'Find ground killer
                        Find_Pilot_By(sInput, sPilot)
                        If sPilot <> "" Then
                            For iPilot = totPilotRS To 1 Step -1
                                If sPilot = PilotRs(iPilot).Name Then

                                    Find_Ground_Type(sInput, _
                                                     sType, _
                                                     PilotRs(iPilot).Side, _
                                                     Stat, _
                                                     Col, _
                                                     Ship, _
                                                     Train, _
                                                     Infantry)
                                    With PilotRs(iPilot)
                                        Select Case sType
                                            Case "Factory"
                                                .Fact += 1
                                            Case "Car"
                                                .Grnd += 1
                                            Case "Tank"
                                                .Tank += 1
                                            Case "Aircraft"
                                                .AC += 1
                                            Case "Train"
                                                .Train += 1
                                            Case "Ship"
                                                .Ship += 1
                                            Case "Gun"
                                                .Gun += 1
                                            Case "FriendGnd"
                                                .FriendGnd += 1
                                            Case "Radar"
                                                .Grnd += 1
                                            Case "Infantry"
                                                .Infantry += 1
                                            Case "Bridge"
                                                .Bridge += 1
                                            Case Else
                                                .Grnd += 1
                                        End Select
                                    End With
                                    Exit For
                                End If
                            Next
                        End If
                    End If
                End If
            Loop

            sEventDate = Replace(sEventDate, "[", "")
            sEventDate = Replace(sEventDate, "]", "")
            myDate = CDate(sEventDate)
            sEventDate = Format(myDate, "yyyyMMddhhmm")
            sResultsFile = INI_Settings.sCampaign & "\Results\"
            If My.Computer.FileSystem.DirectoryExists(sResultsFile) Then
                My.Computer.FileSystem.CreateDirectory(sResultsFile)
            End If
            sResultsFile = sResultsFile & sEventDate & ".csv"
            sb.AppendLine("Pilot" & "," & _
                            "Side" & "," & _
                            "Aircraft" & "," & _
                            "Base" & "," & _
                            "BaseLanded" & "," & _
                            "Status" & "," & _
                            "ACStatus" & "," & _
                            "Kills" & "," & _
                            "Ground" & "," & _
                            "Tanks" & "," & _
                            "Trains" & "," & _
                            "Ships" & "," & _
                            "Parked_AC" & "," & _
                            "Factory" & "," & _
                            "Gun" & "," & _
                            "FriendAC" & "," & _
                            "FriendGnd" & "," & _
                            "Supply_Mission" & "," & _
                            "Time" & "," & _
                            "Ferry_Mission" & "," & _
                            "Infantry" & "," & _
                            "Plates" & "," & _
                            "Bridges" & ",")
            For iPilot = 1 To totPilotRS
                With PilotRs(iPilot)
                    If .ACStatus = "inflight" Then
                        .InFlight = 0
                    End If
                    sOutput = .Name & "," & _
                                Format(.Side, " 0") & "," & _
                                .Coop & "," & _
                                .Base & "," & _
                                .BaseLanded & "," & _
                                .PltStatus & "," & _
                                .ACStatus & "," & _
                                Format(.Kills, " 00") & "," & _
                                Format(.Grnd, " 00") & "," & _
                                Format(.Tank, " 00") & "," & _
                                Format(.Train, " 00") & "," & _
                                Format(.Ship, " 00") & "," & _
                                Format(.AC, " 00") & "," & _
                                Format(.Fact, " 00") & "," & _
                                Format(.Gun, " 00") & "," & _
                                Format(.FriendAC, " 00") & "," & _
                                Format(.FriendGnd, " 00") & "," & _
                                Format(.SupplyMis, " 00") & "," & _
                                Format(.InFlight, "00") & "," & _
                                Format(.FerryMis, "00") & "," & _
                                Format(.Infantry, "00") & "," & _
                                Format(.Plate, " 00") & "," & _
                                Format(.Bridge, " 00") & ","
                End With
                sb.AppendLine(sOutput)
            Next
            'Using outfile As New StreamWriter(sResultsFile)
            'outfile.Write(sb.ToString())
            'outfile.Close()
            'End Using
            Try
                FileSystem.MkDir(INI_Settings.sCampaign & "\Results\")
            Catch
            End Try
            FileOpen(1, sResultsFile, OpenMode.Output, OpenAccess.Write, OpenShare.Shared)
            Print(1, sb.ToString)
            FileClose(1)
        End If
    End Sub
    Public Sub Find_Pilot_Name(ByRef sLog As String, _
                               ByRef sPilot As String, _
                               ByRef sAC As String)
        Dim iPos As Integer
        sLog = Replace(sLog, "(0)", "")
        sPilot = ""
        sAC = ""
        iPos = InStr(sLog, "] ")
        If iPos < 1 Then Exit Sub
        sPilot = Trim(Mid(sLog, iPos + 1))
        sAC = Trim(Mid(sLog, iPos + 1))
        iPos = InStr(sPilot, ":")
        If iPos < 2 Then
            sPilot = ""
            sAC = ""
            Exit Sub
        End If
        sPilot = Left(sPilot, iPos - 1)
        sAC = Mid(sAC, iPos + 1)
        iPos = InStr(sAC, " ")
        sAC = Left(sAC, iPos - 1)
    End Sub
    Public Sub Find_Base(ByRef dX As Double, _
                        ByRef dY As Double, _
                        ByRef sBase As String, _
                        ByRef iBase As Integer, _
                        ByRef iBP As Integer, _
                        ByRef BornPlace() As BornPlaceClass, _
                        ByRef INI_Settings As INI_Class)

        Dim dD As Double
        dD = INI_Settings.BornPlaceRadius
        Dim i As Integer
        For i = BornPlace.Length - 1 To 1 Step -1
            With BornPlace(i)
                If dD > Math.Sqrt(((dX - .X) ^ 2) + ((dY - .Y) ^ 2)) Then
                    dD = Math.Sqrt(((dX - .X) ^ 2) + ((dY - .Y) ^ 2))
                    sBase = .Loc
                    iBase = .intLoc
                    iBP = i
                End If
            End With
        Next
    End Sub
    Public Sub Find_Takeoff_Base(ByRef dX As Double, _
                        ByRef dY As Double, _
                        ByRef sBase As String, _
                        ByRef iBase As Integer, _
                        ByRef iBP As Integer, _
                        ByRef BornPlace() As BornPlaceClass)

        Dim dD As Double
        dD = 200000
        Dim i As Integer
        For i = BornPlace.Length - 1 To 1 Step -1
            With BornPlace(i)
                If dD > Math.Sqrt(((dX - .X) ^ 2) + ((dY - .Y) ^ 2)) Then
                    dD = Math.Sqrt(((dX - .X) ^ 2) + ((dY - .Y) ^ 2))
                    sBase = .Loc
                    iBase = .intLoc
                    iBP = i
                End If
            End With
        Next
    End Sub
    Public Sub Find_Pilot_By(ByRef sLog As String, _
                             ByRef sPilot As String)
        Dim iPos As Integer
        iPos = InStr(sLog, "by ")
        If iPos < 1 Then Exit Sub
        sPilot = Trim(Mid(sLog, iPos + 3))
        iPos = InStr(sPilot, ":")
        If iPos < 2 Then
            sPilot = ""
            Exit Sub
        End If
        sPilot = Left(sPilot, iPos - 1)
    End Sub
    Public Sub Find_Ground_Type(ByRef sLog As String, _
                                ByRef sType As String, _
                                ByRef iSide As Integer, _
                                ByRef Stat() As Stationary, _
                                ByRef Col() As Column, _
                                ByRef Ship() As Column, _
                                ByRef Train() As Column, _
                                ByRef Infantry() As Column)
        'Finds the destroyed unit type for Gen Results
        Dim iPos As Integer
        Dim iUnit As Integer
        If sLog.Contains("ridge") Then
            sType = "Bridge"
            Exit Sub
        End If
        iPos = InStr(sLog, "] ")
        If iPos < 1 Then Exit Sub
        sType = Trim(Mid(sLog, iPos + 1))
        iPos = InStr(sType, " ")
        If iPos < 2 Then
            sType = ""
            Exit Sub
        End If
        sType = Left(sType, iPos - 1)
        If InStr(sType, "_fact") > 0 Then
            sType = "Factory"
            Exit Sub
        End If
        
        If InStr(sType, "_Static") > 0 Then
            For iUnit = 1 To Stat.Length - 1
                If sType = Stat(iUnit).Ident Then
                    If iSide <> Stat(iUnit).Side Then
                        sType = "Car"
                        If InStr(Stat(iUnit).Unit, ".Plane$") > 0 Then sType = "Aircraft"
                        If InStr(Stat(iUnit).Unit, ".Artillery$") > 0 Then sType = "Gun"
                        If InStr(Stat(iUnit).Unit, ".Ship$") > 0 Then sType = "Ship"
                        If InStr(Stat(iUnit).Unit, "$Wagon") > 0 Then sType = "Train"
                    Else
                        sType = "FriendGnd"
                    End If
                    Exit For
                End If
            Next
            Exit Sub
        End If
        If InStr(sType, "_Chief") > 0 Then
            iPos = InStr(sType, "_Chief")
            iPos = iPos + 5
            sType = Left(sType, iPos)
            For iUnit = 1 To Col.Length - 1
                If sType = Col(iUnit).Ident Then
                    If Col(iUnit).Side <> iSide Then
                        sType = "Car"
                        If InStr(Col(iUnit).Unit, "Armor.") > 0 Then
                            sType = "Tank"
                        End If

                    Else
                        sType = "FriendGnd"
                    End If
                    Exit For
                End If
            Next
            For iUnit = 1 To Infantry.Length - 1
                If sType = Infantry(iUnit).Ident Then
                    If Infantry(iUnit).Side <> iSide Then
                        sType = "Infantry"
                    Else
                        sType = "FriendGnd"
                    End If
                    Exit For
                End If
            Next
            For iUnit = 1 To Ship.Length - 1
                If sType = Ship(iUnit).Ident Then
                    If Ship(iUnit).Side <> iSide Then
                        sType = "Ship"
                    Else
                        sType = "FriendGnd"
                    End If
                    Exit For
                End If
            Next
            For iUnit = 1 To Train.Length - 1
                If sType = Train(iUnit).Ident Then
                    If Train(iUnit).Side <> iSide Then
                        sType = "Train"
                    Else
                        sType = "FriendGnd"
                    End If
                    Exit For
                End If
            Next
            Exit Sub
        End If
    End Sub
    Public Sub ProcessEventsAC(ByRef BornPlace() As BornPlaceClass, _
                                ByRef MissSettings As Mission, _
                                ByRef Stat() As Stationary, _
                                ByRef Ship() As Column, _
                                ByRef Infantry() As Column, _
                                ByRef Locat() As Location, _
                                ByRef strDebrief() As String, _
                                ByRef Pilot() As Plt, _
                                ByRef Squad() As Squad_Type, _
                                ByRef SupplyAC() As AC_Supply, _
                                ByRef INI_Settings As INI_Class)
        Dim strEventFile As String = ""
        Dim strInput As String = ""
        Dim strID As String = ""
        Dim strUnit As String = ""
        Dim intStart As Integer
        Dim intID As Integer
        Dim strValue As String = ""
        Dim strOutput As String = ""
        Dim dblX As Double
        Dim dblY As Double
        Dim iH As Integer
        Dim sLoc As String = ""
        Dim iLoc As Integer
        Dim sPilot As String = ""
        Dim iPilot As Integer
        Dim sAC As String = ""
        Dim iAC As Integer
        Dim iBase As Integer
        Dim sBase As String = ""
        Dim iBP As Integer
        Dim iSupply As Integer
        Dim iPos As Integer
        Dim filereader As IO.StreamReader
        Dim sInput As String = ""
        'This sub removes destroyed aircraft from the aircraft files
        strEventFile = INI_Settings.sServer & "\eventlog.dcg"
        If Dir(strEventFile) = "" Then

            ReDim Preserve strDebrief(strDebrief.Length)
            strDebrief(strDebrief.Length - 1) = "Possible error cannot find EVENTLOG FILE !"
            Exit Sub
        End If
        If My.Computer.FileSystem.FileExists(strEventFile) Then
            filereader = My.Computer.FileSystem.OpenTextFileReader(strEventFile)
            Do Until filereader.EndOfStream
                strInput = filereader.ReadLine
                If InStr(strInput, " destroyed by ") > 0 Then
                    FindIDinBY(strInput, strID)
                    If InStr(strID, "_Static") > 0 Then
                        FindStatic(strID, _
                                   intID, _
                                   Stat)
                        If intID > 1 Then
                            intStart = InStr(Stat(intID).Unit, ".Plane$")
                            If intStart > 0 Then
                                intStart = intStart + 7
                                strValue = Mid(Stat(intID).Unit, intStart)
                                RemoveACGround(strValue, _
                                               Stat(intID).intLoc, _
                                               Squad)
                                intStart = InStr(Stat(intID).Unit, "$") + 1
                                strUnit = Mid(Stat(intID).Unit, intStart)
                                FindGrid(Locat(Stat(intID).intLoc).X, Locat(Stat(intID).intLoc).Y, strOutput)

                                ReDim Preserve strDebrief(strDebrief.Length)
                                strDebrief(strDebrief.Length - 1) = strUnit & " destroyed on the ground at " & Stat(intID).Loc & strOutput
                                Stat(intID).Active = False
                            End If
                        End If
                    End If
                End If

                intStart = InStr(strInput, "(0) seat occupied by") 'find base
                If intStart > 0 Then
                    Find_Pilot_Name(strInput, sPilot, sAC)
                    If sPilot <> "" Then
                        FindPilot(sPilot, _
                                  iPilot, _
                                  Pilot)
                        If iPilot > 0 And Pilot(iPilot).Status < 1 Then
                            With Pilot(iPilot)
                                intStart = InStr(strInput, " at ") + 4
                                strValue = Trim(Mid(strInput, intStart))
                                FindCoor(strValue, dblX, dblY, iH)
                                sBase = ""
                                iBase = 0
                                iBP = 0
                                Find_Takeoff_Base(dblX, dblY, _
                                                    sBase, _
                                                    iBase, _
                                                    iBP, _
                                                    BornPlace)

                                'Find Squad(BP and AC)
                                If iBase > 0 Then
                                    For iPos = Squad.Length - 1 To 1 Step -1
                                        If Squad(iPos).DF = sAC And _
                                                Squad(iPos).iLoc = iBase And _
                                                Squad(iPos).Number > 0 Then
                                            Squad(iPos).Number = Squad(iPos).Number - 1
                                            .iSquad = iPos
                                            .Base = sBase
                                            .iBase = iBase
                                            .iBP = iBP
                                            .Status = 1
                                            .Coop = sAC
                                            Exit For
                                        End If
                                    Next
                                    If iPos < 1 Then
                                        .Status = 0
                                        .Base = ""
                                        .iBP = 0
                                        .iSquad = 0
                                        .Coop = ""
                                        .Status = 0
                                    End If
                                End If
                            End With
                        End If
                    End If
                End If


                intStart = InStr(strInput, " in flight at ") 'find location where AC took off
                If intStart > 0 Then
                    Find_Pilot_Name(strInput, sPilot, sAC)
                    If sPilot <> "" Then

                        FindPilot(sPilot, _
                                  iPilot, _
                                  Pilot)
                        If iPilot > 0 Then
                            With Pilot(iPilot)
                                If .iBase > 0 Then
                                    ReDim Preserve strDebrief(strDebrief.Length)
                                    strDebrief(strDebrief.Length - 1) = .Name & " inflight at " & .Base & " in " & .Coop
                                Else
                                    .Status = 0
                                    .Base = ""
                                    .iBP = 0
                                    .iSquad = 0
                                    .Coop = ""
                                    .Status = 0
                                End If
                            End With
                        End If
                    End If
                End If

                intStart = InStr(strInput, " seat occupied on carrier") 'find carrier
                If intStart > 0 Then
                    Find_Pilot_Name(strInput, sPilot, sAC)
                    If sPilot <> "" Then
                        FindPilot(sPilot, _
                                  iPilot, _
                                  Pilot)
                        If iPilot > 0 And Pilot(iPilot).Status < 1 Then
                            sBase = ""
                            iBase = 0
                            iBP = 0
                            With Pilot(iPilot)
                                intStart = InStr(strInput, " on carrier")
                                If intStart > 0 Then
                                    sBase = Mid(strInput, intStart + 11)
                                    intStart = InStr(sBase, " by ")
                                    sBase = Trim(Left(sBase, intStart))
                                    strValue = Trim(Mid(strInput, intStart))
                                    For iBase = Ship.Length - 1 To 1 Step -1
                                        If sBase = Ship(iBase).Ident Then
                                            iBase = iBase * -1
                                            Exit For
                                        End If
                                    Next
                                    For iBP = BornPlace.Length - 1 To 1 Step -1
                                        If BornPlace(iBP).Loc = sBase Then Exit For
                                    Next

                                    'Find Squad(BP and AC)
                                    If iBase < 0 Then
                                        For iPos = Squad.Length - 1 To 1 Step -1
                                            If Squad(iPos).DF = sAC And _
                                                    Squad(iPos).iLoc = iBase And _
                                                    Squad(iPos).Number > 0 Then
                                                Squad(iPos).Number = Squad(iPos).Number - 1
                                                .iSquad = iPos
                                                .Base = sBase
                                                .iBase = iBase
                                                .iBP = iBP
                                                .Status = 1
                                                .Coop = sAC
                                                Exit For
                                            End If
                                        Next
                                        If iPos < 1 Then
                                            .Status = 0
                                            .Base = ""
                                            .iBP = 0
                                            .iSquad = 0
                                            .Coop = ""
                                            .Status = 0
                                        End If
                                    End If
                                End If
                            End With
                        End If
                    End If
                End If
                intStart = InStr(strInput, "in flight from carrier") 'find carrier where AC took off
                If intStart > 0 Then
                    Find_Pilot_Name(strInput, sPilot, sAC)
                    If sPilot <> "" Then

                        FindPilot(sPilot, _
                                  iPilot, _
                                  Pilot)
                        If iPilot > 0 Then
                            With Pilot(iPilot)
                                If .iBase < 0 Then
                                    ReDim Preserve strDebrief(strDebrief.Length)
                                    strDebrief(strDebrief.Length - 1) = .Name & " inflight from carrier at " & .Base & " in " & .Coop
                                Else
                                    .Status = 0
                                    .Base = ""
                                    .iBP = 0
                                    .iSquad = 0
                                    .Coop = ""
                                    .Status = 0
                                End If
                            End With
                        End If
                    End If
                End If

                'Shot Down
                intStart = InStr(strInput, " shot down by ")
                If intStart > 0 Then
                    Find_Pilot_Name(strInput, sPilot, sAC)
                    If sPilot <> "" Then
                        FindPilot(sPilot, _
                                  iPilot, _
                                  Pilot)
                        With Pilot(iPilot)
                            If .Status > 0 Then

                                ReDim Preserve strDebrief(strDebrief.Length)
                                strDebrief(strDebrief.Length - 1) = .Name & " shot down in " & .Coop
                                .Status = 0
                                .Base = ""
                                .iBP = 0
                                .iSquad = 0
                                .Coop = ""
                            End If
                        End With
                    End If
                End If
                'Ditched
                intStart = InStr(strInput, " ditched at ")
                If intStart > 0 Then
                    Find_Pilot_Name(strInput, sPilot, sAC)
                    If sPilot <> "" Then
                        FindPilot(sPilot, _
                                  iPilot, _
                                  Pilot)
                        With Pilot(iPilot)
                            If .Status > 0 Then
                                .Status = 0
                                .Base = ""
                                .iBP = 0
                                .iSquad = 0
                                .Coop = ""

                                ReDim Preserve strDebrief(strDebrief.Length)
                                strDebrief(strDebrief.Length - 1) = sPilot & " ditched in " & sAC
                            End If
                        End With
                    End If
                End If

                'Bailed
                intStart = InStr(strInput, "bailed out at")
                If intStart > 0 Then
                    Find_Pilot_Name(strInput, sPilot, sAC)
                    If sPilot <> "" Then
                        FindPilot(sPilot, iPilot, Pilot)
                        With Pilot(iPilot)
                            If .Status > 0 Then
                                If InStr(strInput, "(0)") > 0 Then
                                    'Pilot Bailed Out
                                    ReDim Preserve strDebrief(strDebrief.Length)
                                    strDebrief(strDebrief.Length - 1) = .Name & " bailed from " & .Coop
                                    .Status = 0
                                    .Base = ""
                                    .iBP = 0
                                    .iSquad = 0
                                    .Coop = ""
                                End If
                            End If
                        End With
                    End If
                End If


                'Crashed
                intStart = InStr(strInput, " crashed at ")
                If intStart > 0 Then
                    Find_Pilot_Name(strInput, sPilot, sAC)
                    If sPilot <> "" Then
                        FindPilot(sPilot, _
                                  iPilot, _
                                  Pilot)
                        With Pilot(iPilot)
                            If .Status > 0 Then

                                ReDim Preserve strDebrief(strDebrief.Length)
                                strDebrief(strDebrief.Length - 1) = .Name & " shot down in " & .Coop
                                .Status = 0
                                .Base = ""
                                .iBP = 0
                                .iSquad = 0
                                .Coop = ""

                            End If
                        End With
                    End If
                End If
                'Landed at
                intStart = InStr(strInput, " landed at ")
                If intStart > 0 Then
                    Find_Pilot_Name(strInput, sPilot, sAC)
                    If sPilot <> "" Then
                        FindPilot(sPilot, _
                                  iPilot, _
                                  Pilot)
                        With Pilot(iPilot)
                            If .Status > 0 Then
                                .Status = 2
                                'find base where pilot landed
                                intStart = InStr(strInput, " landed at ") + 11
                                strValue = Trim(Mid(strInput, intStart))
                                FindCoor(strValue, dblX, dblY, iH)
                                sBase = ""
                                iBase = 0
                                iBP = 0
                                Find_Base(dblX, dblY, _
                                    sBase, _
                                    iBase, _
                                    iBP, _
                                    BornPlace, _
                                    INI_Settings)
                                If iBase > 0 Then
                                    If Squad(.iSquad).Side = Locat(iBase).Side Then
                                        If (BornPlace(iBP).Type = 0 And Squad(.iSquad).Type <> 3) Or _
                                                (BornPlace(iBP).Type = 1 And Squad(.iSquad).Type = 1) Or _
                                                (BornPlace(iBP).Type = 2 And Squad(.iSquad).Type = 2) Then
                                            For iPos = 1 To Squad.Length - 1
                                                If Squad(iPos).DF = sAC And _
                                                        Squad(iPos).iLoc = iBase Then

                                                    .iSquad = iPos
                                                    .Base = sBase
                                                    .iBase = iBase
                                                    .iBP = iBP
                                                    Exit For
                                                End If
                                            Next

                                        Else

                                            ReDim Preserve strDebrief(strDebrief.Length)
                                            strDebrief(strDebrief.Length - 1) = .Name & " landed " & sAC & " at wrong base type " & sBase
                                            .Status = 0
                                            .Base = ""
                                            .iBP = 0
                                            .iSquad = 0
                                            .Coop = ""
                                        End If
                                    Else

                                        ReDim Preserve strDebrief(strDebrief.Length)
                                        strDebrief(strDebrief.Length - 1) = .Name & " landed " & sAC & " at enemy base " & sBase
                                        .Status = 0
                                        .Base = ""
                                        .iBP = 0
                                        .iSquad = 0
                                        .Coop = ""
                                    End If
                                Else

                                    ReDim Preserve strDebrief(strDebrief.Length)
                                    strDebrief(strDebrief.Length - 1) = .Name & " ditched " & .Coop
                                    .Status = 0
                                    .Base = ""
                                    .iBP = 0
                                    .iSquad = 0
                                    .Coop = ""

                                End If
                            End If
                        End With
                    End If
                End If

                'Landed on Carrier
                intStart = InStr(strInput, " landed on carrier")
                If intStart > 0 Then
                    Find_Pilot_Name(strInput, sPilot, sAC)
                    If sPilot <> "" Then
                        FindPilot(sPilot, _
                                  iPilot, _
                                  Pilot)
                        With Pilot(iPilot)
                            If .Status > 0 Then
                                .Status = 2
                                'find base where pilot landed
                                iPos = InStr(sInput, " carrier ")
                                sBase = Trim(Mid(sInput, iPos + 8))
                                iPos = InStr(sBase, " at ")
                                sBase = Trim(Left(sBase, iPos))
                                For iBase = Ship.Length - 1 To 1 Step -1
                                    If sBase = Ship(iBase).Ident Then
                                        iBase = iBase * -1
                                        Exit For
                                    End If
                                Next
                                For iBP = BornPlace.Length - 1 To 1 Step -1
                                    If BornPlace(iBP).Loc = sBase Then Exit For
                                Next
                                'Find Squad(BP and AC)
                                If iBase <> 0 Then

                                    If Squad(.iSquad).Side = Ship(iBase * -1).Side Then
                                        If Squad(.iSquad).Type = 1 Then
                                            For iPos = 1 To Squad.Length - 1
                                                If Squad(iPos).DF = sAC And _
                                                        Squad(iPos).iLoc = iBase Then

                                                    .iSquad = iPos
                                                    .Base = sBase
                                                    .iBase = iBase
                                                    .iBP = iBP
                                                    Exit For
                                                End If
                                            Next
                                        Else

                                            ReDim Preserve strDebrief(strDebrief.Length)
                                            strDebrief(strDebrief.Length - 1) = .Name & " landed " & sAC & " at wrong base type " & sBase
                                            .Status = 0
                                            .Base = ""
                                            .iBP = 0
                                            .iSquad = 0
                                            .Coop = ""
                                        End If
                                    Else

                                        ReDim Preserve strDebrief(strDebrief.Length)
                                        strDebrief(strDebrief.Length - 1) = .Name & " landed " & sAC & " at enemy base " & sBase
                                        .Status = 0
                                        .Base = ""
                                        .iBP = 0
                                        .iSquad = 0
                                        .Coop = ""
                                    End If
                                Else

                                    ReDim Preserve strDebrief(strDebrief.Length)
                                    strDebrief(strDebrief.Length - 1) = .Name & " ditched " & .Coop
                                    .Status = 0
                                    .Base = ""
                                    .iBP = 0
                                    .iSquad = 0
                                    .Coop = ""

                                End If
                            End If
                        End With
                    End If
                End If


                'Refly
                intStart = InStr(strInput, " entered refly menu")
                If intStart > 0 Then
                    sPilot = Trim(Left(strInput, intStart))
                    intStart = InStr(sPilot, "] ")
                    If intStart + 2 < Len(sPilot) Then
                        sPilot = Trim(Mid(sPilot, intStart + 2))
                        If sPilot <> "" Then
                            FindPilot(sPilot, _
                                      iPilot, _
                                      Pilot)
                            If iPilot > 0 Then
                                With Pilot(iPilot)
                                    If .iSquad > 0 Then
                                        Squad(.iSquad).Number += 1

                                        ReDim Preserve strDebrief(strDebrief.Length)
                                        strDebrief(strDebrief.Length - 1) = .Name & " landed " & .Coop & " at " & .Base
                                    End If
                                    .Status = 0
                                    .Base = ""
                                    .iBP = 0
                                    .iSquad = 0
                                    .Coop = ""
                                End With
                            End If
                        End If
                    End If
                End If
                'Disconnect  has disconnected
                intStart = InStr(strInput, " has disconnected")
                If intStart > 0 Then
                    sPilot = Trim(Left(strInput, intStart))
                    intStart = InStr(sPilot, "] ")
                    If intStart + 2 < Len(sPilot) Then
                        sPilot = Trim(Mid(sPilot, intStart + 2))
                        If sPilot <> "" Then
                            FindPilot(sPilot, _
                                      iPilot, _
                                      Pilot)
                            If iPilot > 0 Then
                                With Pilot(iPilot)
                                    If .iSquad > 0 Then
                                        Squad(.iSquad).Number += 1

                                        ReDim Preserve strDebrief(strDebrief.Length)
                                        strDebrief(strDebrief.Length - 1) = .Name & " exited while inflight " & .Coop & " returned to " & .Base
                                    End If
                                    .Status = 0
                                    .Base = ""
                                    .iBP = 0
                                    .iSquad = 0
                                    .Coop = ""
                                End With
                            End If
                        End If
                    End If
                End If
                'Infantry Mission
                'Para Drop
                intStart = InStr(strInput, "dropped paratroops at")
                If intStart > 0 Then
                    Find_Pilot_Name(strInput, sPilot, sAC)
                    If sPilot <> "" Then
                        FindPilot(sPilot, iPilot, Pilot)
                        With Pilot(iPilot)
                            If MissSettings.ParaDrop > 0 Then
                                'Find Location
                                intStart = InStr(strInput, " at ") + 4
                                strValue = Trim(Mid(strInput, intStart))
                                sLoc = ""
                                iLoc = 0
                                FindCoor(strValue, dblX, dblY, iH)
                                FindWPRange(dblX, _
                                            dblY, _
                                            sLoc, _
                                            iLoc, _
                                            MissSettings.ParaRange, _
                                            Locat)
                                If iLoc > 0 Then
                                    If .Side = 1 Then Locat(iLoc).ParaDrop = Locat(iLoc).ParaDrop + 1
                                    If .Side = 2 Then Locat(iLoc).ParaDrop = Locat(iLoc).ParaDrop - 1
                                    ReDim Preserve strDebrief(strDebrief.Length)
                                    strDebrief(strDebrief.Length - 1) = .Name & " dropped paratroops at " & sLoc
                                End If
                            End If
                        End With
                    End If
                End If
                'Moved Infantry Mission
                intStart = InStr(strInput, " moved ")
                If intStart > 0 Then
                    Find_Pilot_Name(strInput, sPilot, sAC)

                    FindIDinAT(strInput, strID)
                    intStart = InStr(strID, ":")
                    If intStart > 0 Then
                        intStart = InStr(strInput, " at ") + 4
                        strValue = Trim(Mid(strInput, intStart))
                        FindCoor(strValue, dblX, dblY, iH)
                        FindWayPoint(dblX, dblY, _
                                    sLoc, _
                                     iLoc, _
                                     Locat)
                        If iLoc > 0 Then
                            intStart = InStr(strInput, " moved ")
                            strValue = Mid(strInput, intStart + 7)
                            intStart = InStr(strValue, " at ")
                            strValue = Trim(Left(strValue, intStart))
                            If strValue <> "" Then
                                For iPos = Infantry.Length - 1 To 1 Step -1
                                    If strValue = Infantry(iPos).Ident Then Exit For
                                Next
                                If iPos > 0 Then
                                    With Infantry(iPos)
                                        .sFrom = sLoc
                                        .sTo = sLoc
                                        .iFrom = iLoc
                                        .iTo = iLoc
                                    End With

                                    ReDim Preserve strDebrief(strDebrief.Length)
                                    strDebrief(strDebrief.Length - 1) = strID & " dropped infantry at " & sLoc
                                End If
                            End If
                        End If
                    End If
                End If

                'Supply Mission
                intStart = InStr(strInput, " supply mission at ")
                If intStart > 0 Then
                    Find_Pilot_Name(strInput, sPilot, sAC)
                    If SupplyAC.Length > 1 Then
                        For iAC = SupplyAC.Length - 1 To 1 Step -1
                            If sAC = SupplyAC(iAC).DF Then
                                iSupply = SupplyAC(iAC).Supply
                                Exit For
                            End If
                        Next
                        If iAC < 1 Then iSupply = 5
                    Else
                        iSupply = 5
                    End If
                    FindIDinAT(strInput, strID)
                    intStart = InStr(strID, ":")
                    If intStart > 0 Then
                        intStart = InStr(strInput, " supply mission at ") + 19
                        strValue = Trim(Mid(strInput, intStart))
                        FindCoor(strValue, dblX, dblY, iH)
                        FindWayPoint(dblX, dblY, _
                                    sLoc, _
                                     iLoc, _
                                     Locat)
                        If iLoc > 0 Then
                            Locat(iLoc).Supply = Locat(iLoc).Supply + iSupply
                            Locat(iLoc).Fuel = Locat(iLoc).Fuel + iSupply

                            ReDim Preserve strDebrief(strDebrief.Length)
                            strDebrief(strDebrief.Length - 1) = strID & " flew supply mission to " & sLoc
                        End If
                    End If
                End If
                'Start Supply Mission
                intStart = InStr(strInput, " supply start at ")
                If intStart > 0 Then
                    Find_Pilot_Name(strInput, sPilot, sAC)
                    If SupplyAC.Length > 1 Then
                        For iAC = SupplyAC.Length - 1 To 1 Step -1
                            If sAC = SupplyAC(iAC).DF Then
                                iSupply = SupplyAC(iAC).Supply
                                Exit For
                            End If
                        Next
                        If iAC < 1 Then iSupply = 5
                    Else
                        iSupply = 5
                    End If
                    FindIDinAT(strInput, strID)
                    intStart = InStr(strID, ":")
                    If intStart > 0 Then
                        intStart = InStr(strInput, " supply start at ") + 17
                        strValue = Trim(Mid(strInput, intStart))
                        FindCoor(strValue, dblX, dblY, iH)
                        FindWayPoint(dblX, dblY, _
                                    sLoc, _
                                     iLoc, _
                                     Locat)
                        If iLoc > 0 Then
                            Locat(iLoc).Supply = Locat(iLoc).Supply - iSupply
                            If Locat(iLoc).Supply < 0 Then Locat(iLoc).Supply = 0
                            Locat(iLoc).Fuel = Locat(iLoc).Fuel - iSupply
                            If Locat(iLoc).Fuel < 0 Then Locat(iLoc).Fuel = 0

                            ReDim Preserve strDebrief(strDebrief.Length)
                            strDebrief(strDebrief.Length - 1) = strID & " started supply mission from " & sLoc
                        End If
                    End If
                End If
                'Supply Drop
                intStart = InStr(strInput, " supply drop at ")
                If intStart > 0 Then
                    Find_Pilot_Name(strInput, sPilot, sAC)
                    If SupplyAC.Length > 1 Then
                        For iAC = SupplyAC.Length - 1 To 1 Step -1
                            If sAC = SupplyAC(iAC).DF Then
                                iSupply = SupplyAC(iAC).Supply
                                Exit For
                            End If
                        Next
                        If iAC < 1 Then iSupply = 5
                    Else
                        iSupply = 5
                    End If
                    FindIDinAT(strInput, strID)
                    intStart = InStr(strID, ":")
                    If intStart > 0 Then
                        intStart = InStr(strInput, " supply drop at ") + 16
                        strValue = Trim(Mid(strInput, intStart))
                        FindCoor(strValue, dblX, dblY, iH)
                        FindWPRange(dblX, dblY, _
                                    sLoc, _
                                     iLoc, _
                                    MissSettings.AirDropRange, _
                                    Locat)
                        If iLoc > 0 Then
                            Locat(iLoc).Supply = Locat(iLoc).Supply + iSupply
                            Locat(iLoc).Fuel = Locat(iLoc).Fuel + iSupply

                            ReDim Preserve strDebrief(strDebrief.Length)
                            strDebrief(strDebrief.Length - 1) = strID & " flew drop mission to " & sLoc
                        End If
                    End If
                End If
                'Mission End
                intStart = InStr(strInput, " Mission END")
                If intStart > 0 And Pilot.Length > 1 Then
                    For iPilot = 1 To Pilot.Length - 1
                        With Pilot(iPilot)
                            If .Status > 0 Then
                                If .iSquad > 0 Then
                                    Squad(.iSquad).Number = Squad(.iSquad).Number + 1
                                End If
                                .Status = 0
                                .Base = ""
                                .iBP = 0
                                .iSquad = 0
                                .Coop = ""
                            End If
                        End With
                    Next
                End If
            Loop
            filereader.Close()
        Else

            ReDim Preserve strDebrief(strDebrief.Length)
            strDebrief(strDebrief.Length - 1) = "Possible error cannot find EVENTLOG FILE !"
        End If
    End Sub

    Public Sub Cleanup_Troops(ByRef Rocket() As RocketType, _
                                ByRef Stat() As Stationary, _
                                ByRef Col() As Column, _
                                ByRef Locat() As Location, _
                                ByRef Infantry() As Column)
        Dim iLoc As Integer
        Dim i As Integer
        If Locat.Length > 1 Then
            For iLoc = 1 To Locat.Length - 1
                With Locat(iLoc)
                    .Allied = 0
                    .Axis = 0
                End With
            Next
        End If
        If Col.Length > 1 Then
            For i = 1 To Col.Length - 1
                With Col(i)
                    If .Side = 1 And .iFrom > 0 Then
                        If .ConType > 0 Then
                            'Locat(.iFrom).Allied += Int(.Troops * .Curr / .Size)
                            Locat(.iFrom).Allied += Int(.Troops * .Curr / .OrigSize)
                        Else
                            Locat(.iFrom).Allied += .Curr * ptTank
                        End If
                    End If
                    If .Side = 2 And .iFrom > 0 Then
                        If .ConType > 0 Then
                            'Locat(.iFrom).Axis += Int(.Troops * .Curr / .Size)
                            Locat(.iFrom).Axis += Int(.Troops * .Curr / .OrigSize)
                        Else
                            Locat(.iFrom).Axis += .Curr * ptTank
                        End If
                    End If
                End With
            Next
        End If
        If Infantry.Length > 1 Then
            For i = 1 To Infantry.Length - 1
                With Infantry(i)
                    If .Side = 1 And .iFrom > 0 Then
                        Locat(.iFrom).Allied += .Curr
                    End If
                    If .Side = 2 And .iFrom > 0 Then
                        Locat(.iFrom).Axis += .Curr
                    End If
                End With
            Next
        End If
        If Stat.Length > 1 Then
            For i = 1 To Stat.Length - 1
                With Stat(i)
                    If .Side = 1 And .Active Then
                        If InStr(.Unit, "vehicles.artillery") > 0 Or _
                                InStr(.Unit, "ships.Ship$") > 0 Then
                            If InStr(.Unit, "vehicles.artillery") > 0 Then
                                Locat(.intLoc).Allied += ptAAA
                            Else
                                Locat(.intLoc).Allied += ptShip
                            End If
                        Else
                            If InStr(.Unit, "vehicles.stationary.Siren") < 1 And _
                                    InStr(.Unit, "planes.Plane$") < 1 Then
                                Locat(.intLoc).Allied += ptCar
                            End If
                        End If
                    End If
                    If .Side = 2 And .Active Then
                        If InStr(.Unit, "vehicles.artillery") > 0 Or _
                                InStr(.Unit, "ships.Ship$") > 0 Then
                            If InStr(.Unit, "vehicles.artillery") > 0 Then
                                Locat(.intLoc).Axis += ptAAA
                            Else
                                Locat(.intLoc).Axis += ptShip
                            End If
                        Else
                            If InStr(.Unit, "vehicles.stationary.Siren") < 1 And _
                                    InStr(.Unit, "planes.Plane$") < 1 Then
                                Locat(.intLoc).Axis += ptCar
                            End If
                        End If
                    End If
                End With
            Next
        End If
        If Rocket.Length > 1 Then
            For i = 1 To Rocket.Length - 1
                With Rocket(i)
                    If .Side = 1 And .Active Then
                        Locat(.intLoc).Allied += ptRocket
                    End If
                    If .Side = 2 And .Active Then
                        Locat(.intLoc).Axis += ptRocket
                    End If
                End With
            Next
        End If
    End Sub
    Private Sub LoadActiveBridge(ByRef ActiveBridge() As String, _
                                ByRef INI_Settings As INI_Class)
        Dim strDBFile As String
        Dim strInput As String
        Dim filereader As IO.StreamReader
        strDBFile = INI_Settings.sCampaign & "\activebridge.dcg"
        ReDim ActiveBridge(0)
        If My.Computer.FileSystem.FileExists(strDBFile) Then
            filereader = My.Computer.FileSystem.OpenTextFileReader(strDBFile)
            Do Until filereader.EndOfStream
                strInput = filereader.ReadLine
                strInput = Trim(strInput)
                If strInput <> "" Then
                    ReDim Preserve ActiveBridge(ActiveBridge.Length)
                    ActiveBridge(ActiveBridge.Length - 1) = strInput
                End If
            Loop
            filereader.Close()
        End If
    End Sub
    Private Function FindTime(ByRef sInput As String) As Date
        Dim sTime As String
        Dim iPos As Integer
        sTime = Trim(sInput)
        iPos = InStr(sTime, "]")
        If iPos > 2 Then
            sTime = Left(sTime, iPos - 1)
            sTime = Mid(sTime, 2)
            FindTime = CDate(sTime)
        Else
            FindTime = #12:00:00 AM#
        End If
    End Function
    Private Sub LoadMODS(ByRef MODS() As String, _
                            ByRef INI_Settings As INI_Class)
        Dim strFile As String
        Dim sInput As String
        Dim filereader As IO.StreamReader
        ReDim MODS(0)
        'Load M0DS
        strFile = INI_Settings.sCampaign & "\mods.dcg"
        If My.Computer.FileSystem.FileExists(strFile) Then
            filereader = My.Computer.FileSystem.OpenTextFileReader(strFile)
            Do Until filereader.EndOfStream
                sInput = Trim(filereader.ReadLine)
                If sInput <> "" Then
                    If sInput = "[Mods]" Or sInput = "[MODS]" Then
                        ReDim MODS(MODS.Length)
                        MODS(MODS.Length - 1) = sInput
                    Else
                        If MODS.Length > 1 Then
                            ReDim Preserve MODS(MODS.Length)
                            MODS(MODS.Length - 1) = "  " & sInput
                        End If
                    End If
                End If
            Loop
            filereader.Close()
        End If
    End Sub
    Private Sub LoadMDS(ByRef MDS() As String, _
                            ByRef INI_Settings As INI_Class)
        Dim strFile As String
        Dim sInput As String
        Dim filereader As IO.StreamReader
        ReDim MDS(0)
        'Load MDS
        strFile = INI_Settings.sCampaign & "\mds.dcg"
        If My.Computer.FileSystem.FileExists(strFile) Then
            filereader = My.Computer.FileSystem.OpenTextFileReader(strFile)
            Do Until filereader.EndOfStream
                sInput = Trim(filereader.ReadLine)
                If sInput <> "" Then
                    If sInput.StartsWith("[MDS") Then
                        ReDim Preserve MDS(MDS.Length)
                        MDS(MDS.Length - 1) = sInput
                    Else
                        'If MDS.Length > 1 Then
                        ReDim Preserve MDS(MDS.Length)
                        MDS(MDS.Length - 1) = "  " & sInput
                        'End If
                    End If
                End If
            Loop
            filereader.Close()
        End If
    End Sub
    Public Sub Find_Moving_Locations(ByRef Stat() As Stationary, _
                                        ByRef Locat() As Location, _
                                        ByRef Station() As Location, _
                                        ByRef Harbor() As Location, _
                                        ByRef INI_Settings As INI_Class)
        Dim Loc1 As Integer
        Dim Loc2 As Integer
        Dim dDist As Double
        If Locat.Length > 2 Then
            For Loc1 = 1 To Locat.Length - 1
                With Locat(Loc1)
                    Select Case INI_Settings.iMovingDF
                        Case Is < 1
                            .Moving = False
                        Case Is > 1
                            .Moving = True
                        Case Else
                            .Moving = False
                            For Loc2 = 1 To Locat.Length - 1
                                If .Side <> Locat(Loc2).Side Then
                                    dDist = Math.Sqrt(((.X - Locat(Loc2).X) ^ 2) + (.Y - Locat(Loc2).Y) ^ 2)
                                    dDist = dDist * 10 ^ -3
                                    If INI_Settings.iMovingDist > dDist Then
                                        .Moving = True
                                        Exit For
                                    End If
                                End If
                            Next
                    End Select
                End With
            Next
        End If
        If Stat.Length > 1 Then
            For Loc1 = 1 To Station.Length - 1
                With Station(Loc1)
                    If INI_Settings.iMovingDF > 0 Then
                        .Moving = True
                    Else
                        .Moving = False
                    End If
                End With
            Next
        End If
        If Harbor.Length > 1 Then
            For Loc1 = 1 To Harbor.Length - 1
                With Harbor(Loc1)
                    If INI_Settings.iMovingDF > 0 Then
                        .Moving = True
                    Else
                        .Moving = False
                    End If
                End With
            Next
        End If
    End Sub
    Public Sub SupplyAircraft(ByRef ac_new() As AC_Type, _
                                ByRef SupplyAC() As AC_Supply)
        Dim i As Integer
        Dim iAC As Integer
        If SupplyAC.Length < 2 Then Exit Sub
        For iAC = 1 To SupplyAC.Length - 1
            For i = ac_new.Length - 1 To 1 Step -1
                If SupplyAC(iAC).Coop = ac_new(i).Coop Then
                    SupplyAC(iAC).DF = ac_new(i).DF
                    Exit For
                End If
            Next
            If i < 1 Then SupplyAC(iAC).DF = SupplyAC(iAC).Coop
        Next
    End Sub
    Public Sub LoadRadarFile(ByRef StructInfo() As Building, _
                                ByRef Locat() As Location, _
                                ByRef strDebrief() As String, _
                                ByRef Radar() As Factory, _
                                ByRef strError As String, _
                                ByRef INI_Settings As INI_Class)
        Dim bolerror As Boolean
        Dim strRadarFile As String
        Dim strInput As String
        Dim intPos As Integer
        Dim intStart As Integer
        Dim filereader As IO.StreamReader
        strRadarFile = INI_Settings.sCampaign & "\radar.dcg"
        If My.Computer.FileSystem.FileExists(strRadarFile) Then
            filereader = My.Computer.FileSystem.OpenTextFileReader(strRadarFile)
            Do Until filereader.EndOfStream
                strInput = Trim(filereader.ReadLine)
                intStart = InStr(strInput, "_rad")
                If intStart > 0 Then
                    ReDim Preserve Radar(Radar.Length)
                    Radar(Radar.Length - 1).Active = True
                    strInput = Trim(strInput)
                    With Radar(Radar.Length - 1)
                        If Left(strInput, 1) = "X" Then
                            .Active = False
                            intStart = 3
                        Else
                            .Active = True
                            intStart = 1
                        End If
                        intPos = InStr(intStart, strInput, " ")
                        .ID = Trim(Mid(strInput, intStart, intPos - intStart))
                        intStart = intPos + 1
                        intPos = InStr(intStart, strInput, " ")
                        .Unit = Trim(Mid(strInput, intStart, intPos - intStart))
                        intStart = intPos + 1
                        intPos = InStr(intStart, strInput, " ")
                        .Side = Int(Val(Mid(strInput, intStart, intPos - intStart)))
                        intStart = intPos + 1
                        intPos = InStr(intStart, strInput, " ")
                        .X = Val(Mid(strInput, intStart, intPos - intStart))
                        intStart = intPos + 1
                        intPos = InStr(intStart, strInput, " ")
                        .Y = Val(Mid(strInput, intStart, intPos - intStart))
                        intStart = intPos + 1
                        .Head = Int(Val(Mid(strInput, intStart)))
                        FindStructure(bolerror, _
                            strError, _
                            .Unit, _
                            .Struct, _
                            StructInfo)
                        If .Struct < 1 Then

                            ReDim Preserve strDebrief(strDebrief.Length)
                            strDebrief(strDebrief.Length - 1) = "Possible error - cannot find Radar " & _
                                .ID & " " & .Unit
                        Else
                            .Supply = StructInfo(.Struct).Supply
                            .Troops = StructInfo(.Struct).Troops
                            .Col = StructInfo(.Struct).Cols
                            .Size = StructInfo(.Struct).Size
                            .Curr = StructInfo(.Struct).Size
                            FindWayPoint(.X, _
                                    .Y, _
                                    .Loc, _
                                    .intLoc, _
                                    Locat)
                        End If
                    End With
                End If
            Loop
            filereader.Close()
        End If
    End Sub

    Public Sub GenRadarFile(ByRef Radar() As Factory, _
                            ByRef INI_Settings As INI_Class)
        Dim intLine As Integer
        Dim strOutput As String
        Dim sb As New StringBuilder
        If Radar.Length < 2 Then Exit Sub
        sb.AppendLine("[Radars]")
        For intLine = Radar.Length - 1 To 1 Step -1
            With Radar(intLine)
                If .Active Then
                    strOutput = "  "
                Else
                    strOutput = "X "
                End If
                strOutput = strOutput & .ID & " " & _
                        .Unit & " " & _
                        Format(.Side, "0") & " " & _
                        Format(.X, "0.00") & " " & _
                        Format(.Y, "0.00") & " " & _
                        Format(.Head, "0.00")
            End With
            sb.AppendLine(strOutput)
        Next
        'Using outfile As New StreamWriter(INI_Settings.sCampaign & "\radar.dcg")
        'outfile.Write(sb.ToString())
        'outfile.Close()
        'End Using
        FileOpen(1, INI_Settings.sCampaign & "\radar.dcg", OpenMode.Output, OpenAccess.Write, OpenShare.Shared)
        Print(1, sb.ToString)
        FileClose(1)
    End Sub
    Public Sub PlaceRadarStat(ByRef intRadar As Integer, _
                                ByRef sb As StringBuilder, _
                                ByRef StructList(,) As String, _
                                ByRef Radar() As Factory)
        Dim strOutput As String
        Dim intCount As Integer
        With Radar(intRadar)
            If .Active Then
                For intCount = 1 To .Size
                    strOutput = "  " & .ID & Format(intCount + 1, "0") & " " & _
                        StructList(intCount, .Struct) & " " & _
                        Format(.Side, "0") & " " & _
                        Format(.X, "0.00") & " " & _
                        Format(.Y, "0.00") & " " & _
                        Format(.Head, "0.00")
                    sb.AppendLine(strOutput)
                Next
            End If
        End With
    End Sub
    Public Sub UpdateRadars(ByRef Locat() As Location, _
                                ByRef Radar() As Factory)
        Dim intRadarCnt As Integer
        If Radar.Length < 2 Then Exit Sub

        For intRadarCnt = 1 To Radar.Length - 1
            With Radar(intRadarCnt)
                If Not .Active Then
                    If Locat(.intLoc).Supply > 0 And _
                        .Side = Locat(.intLoc).Side Then
                        If .Supply <= Locat(.intLoc).Supply Then
                            .Active = True
                            Locat(.intLoc).Supply = Locat(.intLoc).Supply - .Supply
                            If .Side = 1 Then
                                Locat(.intLoc).Allied = Locat(.intLoc).Allied + .Troops
                            Else
                                Locat(.intLoc).Axis = Locat(.intLoc).Axis + .Troops
                            End If
                            If Locat(.intLoc).Supply < 0 Then Locat(.intLoc).Supply = 0
                        End If
                    End If
                End If
            End With
        Next
    End Sub
    Public Sub FindRadar(ByRef strID As String, _
                            ByRef intRadar As Integer, _
                            ByRef Radar() As Factory)
        If Radar.Length < 2 Then
            intRadar = 0
            Exit Sub
        End If
        For intRadar = Radar.Length - 1 To 1 Step -1
            If strID = Radar(intRadar).ID Then
                Exit For
            End If
        Next
    End Sub

    Public Sub LoadIRDFile(ByRef camsettings As Campaign, _
                            ByRef Locat() As Location, _
                            ByRef Trail() As Waypoint, _
                            ByRef TrailWP() As String, _
                            ByRef ini_settings As INI_Class)
        'Load Infantry Route File
        Dim strIRDFile As String
        Dim strInput As String
        Dim strValue As String
        Dim intPos As Integer
        Dim intStart As Integer
        Dim iFrom As Integer
        Dim iTo As Integer
        Dim CurrRoute(0) As Waypoint
        Dim intRoute As Integer
        Dim i As Integer
        Dim filereader As IO.StreamReader
        Dim iFile As Integer
        ReDim TrailWP(0)
        For iFile = 1 To 2
            If iFile = 1 Then
                strIRDFile = ini_settings.sData & camsettings.RouteName & ".rds"
            Else
                strIRDFile = ini_settings.sData & camsettings.RouteName & ".ird"
            End If
            If My.Computer.FileSystem.FileExists(strIRDFile) Then
                filereader = My.Computer.FileSystem.OpenTextFileReader(strIRDFile)
                Do Until filereader.EndOfStream
                    strInput = filereader.ReadLine
                    intStart = InStr(strInput, "[")
                    If intStart > 0 Then
                        'find start location
                        If Trail.Length > 1 Then FindTrailLocations(CurrRoute, _
                                                intRoute, _
                                                iFrom, _
                                                iTo, _
                                                Locat, _
                                                Trail)
                        intRoute = 0
                        ReDim CurrRoute(intRoute)
                        intStart = intStart + 1
                        intPos = InStr(strInput, " to ")
                        strValue = Trim(Mid(strInput, intStart, intPos - intStart))
                        FindLoc(strValue, iFrom, _
                                Locat.Length - 1, _
                                Locat)
                        If iFrom < 1 Then
                            ReDim Preserve Locat(Locat.Length)
                            Locat(Locat.Length - 1).Loc = strValue
                            Locat(Locat.Length - 1).Type = 1
                            Locat(Locat.Length - 1).MaxFuel = ini_settings.intMinFuel
                            Locat(Locat.Length - 1).MaxSup = ini_settings.intMinSup
                            iFrom = Locat.Length - 1
                        End If
                        intStart = intPos + 4
                        intPos = InStr(strInput, "]")
                        strValue = Trim(Mid(strInput, intStart, intPos - intStart))
                        FindLoc(strValue, iTo, _
                                Locat.Length - 1, _
                                Locat)
                        If iTo < 1 Then
                            ReDim Preserve Locat(Locat.Length)
                            Locat(Locat.Length - 1).Loc = strValue
                            Locat(Locat.Length - 1).Type = 1
                            iTo = Locat.Length - 1
                        End If
                        ReDim Preserve Trail(Trail.Length)
                        With Trail(Trail.Length - 1)
                            .strFrom = Locat(iFrom).Loc
                            .iFrom = iFrom
                            .strTo = Locat(iTo).Loc
                            .iTo = iTo
                            .Start = TrailWP.Length
                            .iEnd = TrailWP.Length
                            .FrmSpn = .Start + 4
                            .ToSpn = .iEnd - 4
                            Locat(iFrom).RedRoad = Trail.Length - 1
                            Locat(iFrom).RedWp = .Start + 5
                            Locat(iTo).BlueRoad = Trail.Length - 1
                        End With

                    Else
                        If Len(Trim(strInput)) > 0 Then
                            ReDim Preserve TrailWP(TrailWP.Length)
                            i = InStr(strInput, " 0 ")
                            If i > 0 Then
                                TrailWP(TrailWP.Length - 1) = Trim(Left(strInput, i))
                            Else
                                TrailWP(TrailWP.Length - 1) = Trim(strInput)
                            End If
                            If InStr(TrailWP(TrailWP.Length - 1), " -") > 0 Then TrailWP(TrailWP.Length - 1) = Replace(TrailWP(TrailWP.Length - 1), " -", " ")
                            Trail(Trail.Length - 1).iEnd = TrailWP.Length - 1
                            Trail(Trail.Length - 1).ToSpn = Trail(Trail.Length - 1).iEnd - 4
                            Trail(Trail.Length - 1).ToStp = Trail(Trail.Length - 1).iEnd - 6
                            Locat(Trail(Trail.Length - 1).iTo).BlueWP = Trail(Trail.Length - 1).iEnd - 5
                            intRoute = intRoute + 1
                            ReDim Preserve CurrRoute(intRoute)
                            FindCoor(strInput, _
                                    CurrRoute(intRoute).AlliedX, _
                                    CurrRoute(intRoute).AlliedY, _
                                    CurrRoute(intRoute).AlliedH)
                        End If
                    End If
                Loop
                filereader.Close()
                FindTrailLocations(CurrRoute, _
                                        intRoute, _
                                        iFrom, _
                                        iTo, _
                                        Locat, _
                                        Trail)
            End If
        Next
    End Sub
    Public Sub LoadInfantryColumn(ByVal sInput As String, _
                                ByRef Infantry() As Column, _
                                ByRef Locat() As Location)


        Dim intPos As Integer
        Dim intStart As Integer
        Dim s As String
        'This sub loads the infantry columns from the columns.dcg file ito the infantry array
        ReDim Preserve Infantry(Infantry.Length)
        sInput.Trim()
        Dim sInfantry() As String
        sInfantry = sInput.Split(" ")
        With Infantry(Infantry.Length - 1)
            .Direction = 1
            .Size = 1
            .Curr = 1
            .OrigSize = 1
            .Hold = False
            .AllowLoad = 1
            For i = 0 To sInfantry.Length - 1
                If i = 0 Then .Ident = sInfantry(i)
                If i = 1 Then
                    .Unit = sInfantry(i)
                    intStart = 0
                    If InStr(.Unit, "Infantry.") > 0 Then intStart = 10
                    If intStart > 0 Then
                        intPos = InStr(.Unit, "-")
                        .Size = Val(Mid(Infantry(Infantry.Length - 1).Unit, intStart, intPos - intStart))
                        .Curr = Infantry(Infantry.Length - 1).Size
                        .Troops = Infantry(Infantry.Length - 1).Size
                        .OrigSize = 1
                        'copied this section to i=5 after the .Orig has something to get the original size
                        'intPos = InStr(.Orig, "-")
                        'If intPos > 0 Then
                        '.OrigSize = Int(Val(Left(Infantry(Infantry.Length - 1).Orig, intPos - 1)))
                        'End If
                    End If
                End If
                If i = 2 Then .Side = Int(Val(sInfantry(i)))
                If i = 3 Then .sFrom = sInfantry(i).Replace("@", "")
                If i = 4 Then .sTo = sInfantry(i).Replace("@", "")
                If i = 5 Then
                    .Orig = sInfantry(i).Replace("$", "")
                    intPos = InStr(.Orig, "-")
                    If intPos > 0 Then
                        .OrigSize = Int(Val(Left(Infantry(Infantry.Length - 1).Orig, intPos - 1)))
                    End If
                End If
                If i > 5 Then
                    If sInfantry(i).Contains("D=") Then
                        s = sInfantry(i).Replace("D=", "")
                        .Direction = Int(Val(s))
                    End If
                    If sInfantry(i).Contains("S=") Then
                        s = sInfantry(i).Replace("S=", "")
                        .Size = Int(Val(s))
                        .Curr = Int(Val(s))
                    End If
                    If sInfantry(i).Contains("LOAD=") Then
                        s = sInfantry(i).Replace("LOAD=", "")
                        .AllowLoad = Int(Val(s))
                    End If
                End If
            Next

            FindLoc(.sFrom, _
                    .iFrom, _
                    Locat.Length - 1, _
                    Locat)
            If Infantry(Infantry.Length - 1).sFrom <> "" Then
                FindLoc(.sTo, _
                        .iTo, _
                        Locat.Length - 1, _
                        Locat)
                If .iTo < 0 Or .iFrom < 0 Then
                    If .sTo <> .sFrom Then
                        .sTo = "Blank"
                        .sFrom = "Blank"
                        .iTo = -1
                        .iFrom = -1
                    End If
                End If
            Else
                .sTo = "Blank"
                .sFrom = "Blank"
                .iTo = -1
                .iFrom = -1
            End If
        End With


    End Sub
    Public Sub MoveInfantry(ByRef Infantry() As Column)
        'Moves infantry to next location - infantry not stopped by bridges
        Dim intCount As Integer
        If Infantry.Length < 2 Then Exit Sub
        For intCount = 1 To Infantry.Length - 1
            With Infantry(intCount)
                .sFrom = .sTo
                .iFrom = .iTo
            End With
        Next
    End Sub

    Public Sub UpdateInfantry(ByRef ColLoc() As String, _
                            ByRef Bridge() As Brid, _
                            ByRef MissSettings As Mission, _
                            ByRef Infantry() As Column, _
                            ByRef Locat() As Location, _
                            ByRef Trail() As Waypoint, _
                            ByRef strDebrief() As String, _
                            ByRef RouteStart(,) As Integer, _
                            ByRef INI_Settings As INI_Class)
        Dim intInfantry As Integer
        Dim intLoc As Integer
        Dim sngRnd As Single
        Dim intPosTo As Integer
        Dim PosTo(0) As Waypoint
        Dim intCount As Integer
        Dim intBdgOut As Integer
        Dim strOutput As String
        'This sub decides if an infantry column willl move to the next location
        If Infantry.Length < 2 Then Exit Sub

        For intInfantry = 1 To Infantry.Length - 1
            intBdgOut = 0
            ReDim Preserve ColLoc(ColLoc.Length)
            ColLoc(ColLoc.Length - 1) = Infantry(intInfantry).Ident
            Select Case Infantry(intInfantry).sFrom

                Case Is = "Blank"
                    sngRnd = Rnd()
                    If sngRnd < INI_Settings.ColumnSpawn Then
                        With Infantry(intInfantry)
                            If Locat(RouteStart(.Side, 1)).Side = .Side Then
                                .sFrom = Locat(RouteStart(.Side, 1)).Loc
                                .sTo = Locat(RouteStart(.Side, 1)).Loc
                                .iFrom = RouteStart(.Side, 1)
                                .iTo = RouteStart(.Side, 1)
                                .Direction = 1
                                .AllowLoad = 1
                            End If
                        End With

                    End If
                    ColLoc(ColLoc.Length - 1) = ColLoc(ColLoc.Length - 1) & " @" & Infantry(intInfantry).sFrom
                Case Else
                    'Move Infantry Column
                    ColLoc(ColLoc.Length - 1) = ColLoc(ColLoc.Length - 1) & " @" & Infantry(intInfantry).sFrom
                    If Infantry(intInfantry).iFrom > 0 Then
                        If Infantry(intInfantry).Side = Locat(Infantry(intInfantry).iFrom).Side Then
                            intPosTo = 0

                            Select Case Infantry(intInfantry).Side
                                Case 1
                                    For intLoc = 1 To Trail.Length - 1
                                        If Trail(intLoc).iTo = Infantry(intInfantry).iFrom Then

                                            intPosTo = intPosTo + 1
                                            ReDim Preserve PosTo(intPosTo)
                                            PosTo(intPosTo).iTo = Trail(intLoc).iFrom
                                            PosTo(intPosTo).strTo = Trail(intLoc).strFrom

                                        End If
                                    Next
                                Case 2
                                    For intLoc = 1 To Trail.Length - 1
                                        If Trail(intLoc).iFrom = Infantry(intInfantry).iFrom Then
                                            intPosTo = intPosTo + 1
                                            ReDim Preserve PosTo(intPosTo)
                                            PosTo(intPosTo).iTo = Trail(intLoc).iTo
                                            PosTo(intPosTo).strTo = Trail(intLoc).strTo

                                        End If
                                    Next
                            End Select

                            If intPosTo > 0 Then
                                sngRnd = Rnd() * intPosTo
                                intLoc = Int(sngRnd + 1)
                                intLoc = PosTo(intLoc).iTo
                                Infantry(intInfantry).iTo = intLoc
                                Infantry(intInfantry).sTo = Locat(intLoc).Loc
                                If Infantry(intInfantry).iTo <> Infantry(intInfantry).iFrom And InStr(Infantry(intInfantry).Unit, "Infantry") = 0 Then
                                    Locat(Infantry(intInfantry).iFrom).Fuel = Locat(Infantry(intInfantry).iFrom).Fuel - 2
                                    If Locat(Infantry(intInfantry).iFrom).Fuel < 0 Then Locat(Infantry(intInfantry).iFrom).Fuel = 0
                                End If
                                For intCount = 1 To intPosTo
                                    ColLoc(ColLoc.Length - 1) = ColLoc(ColLoc.Length - 1) & " @" & PosTo(intCount).strTo
                                Next
                            Else
                                With Infantry(intInfantry)
                                    Select Case .Side
                                        Case 1
                                            If .iFrom <> RouteStart(2, 1) Then

                                                ReDim Preserve strDebrief(strDebrief.Length)
                                                strOutput = "Possible error in road system " & Infantry(intInfantry).Ident & " " & Infantry(intInfantry).sFrom
                                                strDebrief(strDebrief.Length - 1) = strOutput
                                            End If
                                        Case Else
                                            If .iFrom <> RouteStart(1, 1) Then

                                                ReDim Preserve strDebrief(strDebrief.Length)
                                                strOutput = "Possible error in road system " & Infantry(intInfantry).Ident & " " & Infantry(intInfantry).sFrom
                                                strDebrief(strDebrief.Length - 1) = strOutput
                                            End If
                                    End Select
                                End With
                            End If
                        End If
                        'Find Locations an Infantry Column might retreat to
                        If Infantry(intInfantry).Side = Locat(Infantry(intInfantry).iFrom).Side And _
                                (Locat(Infantry(intInfantry).iFrom).Fuel > 1 Or InStr(Infantry(intInfantry).Unit, "Infantry") > 0) Then
                            intPosTo = 0
                            Select Case Infantry(intInfantry).Side
                                Case 1
                                    For intLoc = 1 To Trail.Length - 1
                                        If Trail(intLoc).iFrom = Infantry(intInfantry).iFrom Then

                                            intPosTo = intPosTo + 1
                                            ReDim Preserve PosTo(intPosTo)
                                            PosTo(intPosTo).iTo = Trail(intLoc).iTo
                                            PosTo(intPosTo).strTo = Trail(intLoc).strTo

                                        End If
                                    Next


                                Case 2
                                    For intLoc = 1 To Trail.Length - 1
                                        If Trail(intLoc).iTo = Infantry(intInfantry).iFrom Then

                                            intPosTo = intPosTo + 1
                                            ReDim Preserve PosTo(intPosTo)
                                            PosTo(intPosTo).iTo = Trail(intLoc).iFrom
                                            PosTo(intPosTo).strTo = Trail(intLoc).strFrom
                                        End If
                                    Next
                            End Select

                            If intPosTo > 0 Then
                                For intCount = 1 To intPosTo
                                    ColLoc(ColLoc.Length - 1) = ColLoc(ColLoc.Length - 1) & " @" & PosTo(intCount).strTo
                                Next
                            End If
                        End If
                    End If
            End Select
            For iLoc = 1 To Locat.Length - 1
                Locat(iLoc).Infantry = 0
                For iInfantry = 1 To Infantry.Length - 1
                    If Infantry(iInfantry).iFrom = iLoc Then
                        Locat(iLoc).Infantry = Locat(iLoc).Infantry + 1
                    End If
                Next
            Next
        Next
    End Sub

    Public Sub CheckInfantry(ByRef Infantry() As Column, _
                                ByRef Locat() As Location, _
                                ByRef strDebrief() As String)
        'Checks the columns to see if any have been destroyed
        Dim intCount As Integer
        Dim intStart As Integer
        Dim strUnit As String = ""
        Dim strOutput As String = ""
        If Infantry.Length < 2 Then Exit Sub
        For intCount = 1 To Infantry.Length - 1

            With Infantry(intCount)

                'deal with a tank column
                If .Size > .Curr Then
                    .Unit = Replace(.Unit, Chr(48 + .Size), Chr(48 + .Curr), 1, 1)
                    .Size = .Curr
                End If

                If .Curr < 1 Then
                    intStart = InStr(.Unit, ".") + 1
                    strUnit = Mid(.Unit, intStart)
                    If .iFrom > 0 Then
                        FindGrid(Locat(.iFrom).X, Locat(.iFrom).Y, strOutput)

                        ReDim Preserve strDebrief(strDebrief.Length)
                        strDebrief(strDebrief.Length - 1) = strUnit & " at " & .sFrom & strOutput
                    End If
                    .sFrom = "Destroyed"
                    .sTo = "Destroyed"
                    .iFrom = 0
                    .iTo = 0
                    .Curr = .Size
                    RestoreOrigCol(.Unit, .Orig)
                End If
            End With
        Next
    End Sub
    Public Sub PlaceInfantry(ByRef intChief As Integer, _
                                ByRef MissSettings As Mission, _
                                ByRef Infantry() As Column, _
                                ByRef Locat() As Location, _
                                ByRef Trail() As Waypoint, _
                                ByRef Chief() As String, _
                                ByRef ChiefMov() As String, _
                                ByRef ChiefRd() As String, _
                                ByRef TrailWP() As String, _
                                ByRef INI_Settings As INI_Class, _
                                ByRef CamSettings As Campaign)
        Dim intUnit As Integer
        Dim dbX As Double
        Dim dbY As Double
        Dim intHead As Integer
        Dim strUnit As String
        Dim intRd As Integer
        Dim intDir As Integer
        Dim intStart As Integer
        Dim strOutput As String
        If Locat(Infantry(intChief).iTo).Side <> Infantry(intChief).Side Or _
                Locat(Infantry(intChief).iFrom).Side <> Infantry(intChief).Side Then
            PlaceInfantry_Engaged(intChief, _
                                  MissSettings, _
                                  Infantry, _
                                  Locat, _
                                  Trail, _
                                  Chief, _
                                  ChiefMov, _
                                  ChiefRd, _
                                  TrailWP, _
                                  INI_Settings, _
                                  CamSettings)
            Exit Sub
        End If

        With Infantry(intChief)
            If .iFrom = .iTo Then 'Infantry at a named location
                If .Side = 1 Then
                    dbX = Locat(.iFrom).AlliedX
                    dbY = Locat(.iFrom).AlliedY
                    intHead = Locat(.iFrom).AlliedH
                    MoveCoor(Locat(.iFrom).AlliedX, _
                                Locat(.iFrom).AlliedY, _
                                Locat(.iFrom).AlliedH, _
                                INI_Settings.sngStaticSep * (1 + .Size))
                Else
                    dbX = Locat(.iFrom).AxisX
                    dbY = Locat(.iFrom).AxisY
                    intHead = Locat(.iFrom).AxisH
                    MoveCoor(Locat(.iFrom).AxisX, _
                                Locat(.iFrom).AxisY, _
                                Locat(.iFrom).AxisH, _
                                INI_Settings.sngStaticSep * (1 + .Size))
                End If


                intStart = InStr(.Unit, "-")
                intStart = intStart + 1
                strUnit = Trim(Mid(.Unit, intStart))
                If InStr(strUnit, "SU-") > 0 Then strUnit = Replace(strUnit, "SU-", "SU")
                strUnit = "vehicles.artillery.Artillery$" & strUnit
                intDir = Int(Rnd() * 2)
                If intDir = 0 Then intDir = -1
                For intUnit = 1 To .Size
                    MoveCoor(dbX, _
                            dbY, _
                            intHead, _
                            INI_Settings.sngStaticSep)
                    strOutput = "  " & .Ident & Format(intUnit - 1, "0") & _
                                " " & strUnit & _
                                " " & Format(.Side, "0") & _
                                " " & Format(dbX, "########.00") & _
                                " " & Format(dbY, "########.00") & _
                                " " & Format(intHead + 90, "##0.0")
                    If InStr(strOutput, ".artillery") > 0 Then
                        strOutput = strOutput & _
                                Format(INI_Settings.sngTankDly, " 0.0") & " " & _
                                Format(INI_Settings.sngTankRng, "0")
                    Else
                        strOutput = strOutput & " 0.0"
                    End If
                    If InStr(strOutput, ".artillery.Artillery") > 0 And InStr(.Unit, "Infantry.") < 1 Then
                        strOutput = Replace(strOutput, ".artillery.Artillery", ".stationary.Stationary")
                    End If

                    ReDim Preserve Chief(Chief.Length)
                    Chief(Chief.Length - 1) = strOutput
                Next
            Else
                For intRd = Trail.Length - 1 To 1 Step -1
                    If (Trail(intRd).iFrom = .iTo And _
                            Trail(intRd).iTo = .iFrom) Or _
                            (Trail(intRd).iFrom = .iFrom And _
                            Trail(intRd).iTo = .iTo) Then
                        If .Side = 1 Then
                            dbX = Trail(intRd).AlliedX
                            dbY = Trail(intRd).AlliedY
                            intHead = Trail(intRd).AlliedH
                        Else
                            dbX = Trail(intRd).AxisX
                            dbY = Trail(intRd).AxisY
                            intHead = Trail(intRd).AxisH
                        End If
                        Exit For
                    End If
                Next
                If intRd > 1 Then
                    If (Locat(.iFrom).Moving) And _
                              (Trail(intRd).iEnd - Trail(intRd).Start > 2 * (INI_Settings.ColSpawn + 3)) And _
                              ((Trail(intRd).iFrom = .iFrom And Trail(intRd).AxisSP <= INI_Settings.ColSpawn) Or _
                              (Trail(intRd).iTo = .iFrom And Trail(intRd).AlliedSP < INI_Settings.ColSpawn)) Then
                        PlaceInfantryMoving(intChief, _
                                            intRd, _
                                            MissSettings, _
                                            Infantry, _
                                            Trail, _
                                            ChiefMov, _
                                            ChiefRd, _
                                            TrailWP, _
                                            INI_Settings)
                    Else
                        If .Side = 1 Then
                            MoveCoor(Trail(intRd).AlliedX, _
                                Trail(intRd).AlliedY, _
                                Trail(intRd).AlliedH, _
                                INI_Settings.sngStaticSep * (1 + .Size))
                        Else
                            MoveCoor(Trail(intRd).AxisX, _
                                Trail(intRd).AxisY, _
                                Trail(intRd).AxisH, _
                                INI_Settings.sngStaticSep * (1 + .Size))
                        End If
                        intStart = InStr(.Unit, "-")
                        intStart = intStart + 1
                        strUnit = Trim(Mid(.Unit, intStart))
                        If InStr(strUnit, "SU-") > 0 Then strUnit = Replace(strUnit, "SU-", "SU")
                        strUnit = "vehicles.artillery.Artillery$" & strUnit
                        intDir = Int(Rnd() * 2)
                        If intDir = 0 Then intDir = -1
                        For intUnit = 1 To .Size
                            MoveCoor(dbX, _
                                dbY, _
                                intHead, _
                                INI_Settings.sngStaticSep)
                            strOutput = "  " & .Ident & Format(intUnit - 1, "0") & _
                                    " " & strUnit & _
                                    " " & Format(.Side, "0") & _
                                    " " & Format(dbX, "########.00") & _
                                    " " & Format(dbY, "########.00") & _
                                    " " & Format(intHead + 90, "##0.0")
                            If InStr(strOutput, ".artillery") > 0 Then
                                strOutput = strOutput & _
                                    Format(INI_Settings.sngTankDly, " 0.0") & " " & _
                                    Format(INI_Settings.sngTankRng, "0")
                            Else
                                strOutput = strOutput & " 0.0"
                            End If
                            If InStr(strOutput, ".artillery.Artillery") > 0 And InStr(.Unit, "Infantry.") < 1 Then
                                strOutput = Replace(strOutput, ".artillery.Artillery", ".stationary.Stationary")
                            End If

                            ReDim Preserve Chief(Chief.Length)
                            Chief(Chief.Length - 1) = strOutput
                        Next
                    End If
                End If
            End If
        End With
    End Sub

    Public Sub PlaceInfantry_Engaged(ByRef intChief As Integer, _
                                        ByRef MissSettings As Mission, _
                                        ByRef Infantry() As Column, _
                                        ByRef Locat() As Location, _
                                        ByRef Trail() As Waypoint, _
                                        ByRef Chief() As String, _
                                        ByRef ChiefMov() As String, _
                                        ByRef ChiefRd() As String, _
                                        ByRef TrailWP() As String, _
                                        ByRef INI_Settings As INI_Class, _
                                        ByRef CamSettings As Campaign)
        Dim intUnit As Integer
        Dim dbX As Double
        Dim dbY As Double
        Dim intHead As Integer
        Dim strUnit As String
        Dim intRd As Integer
        Dim intDir As Integer
        Dim intRnd As Integer
        Dim intStart As Integer
        Dim strOutput As String
        With Infantry(intChief)
            If .iFrom = .iTo Then 'Infantrys at a named location
                If INI_Settings.iMovingDF > 0 And _
                    ((.Side = 1 And Locat(.iFrom).RedRoad > 0) Or _
                     (.Side = 2 And Locat(.iFrom).BlueRoad > 0)) Then
                    PlaceInfantryAtLocationMoving(intChief, _
                                                  Locat, _
                                                  MissSettings, _
                                                  Infantry, _
                                                  Trail, _
                                                  ChiefMov, _
                                                  ChiefRd, _
                                                  TrailWP, _
                                                  INI_Settings)
                Else
                    If .Side = 1 Then
                        dbX = Locat(.iFrom).AlliedX
                        dbY = Locat(.iFrom).AlliedY
                        intHead = Locat(.iFrom).AlliedH
                        MoveCoor(Locat(.iFrom).AlliedX, _
                                    Locat(.iFrom).AlliedY, _
                                    Locat(.iFrom).AlliedH, _
                                    INI_Settings.sngStaticSep * 2)
                    Else
                        dbX = Locat(.iFrom).AxisX
                        dbY = Locat(.iFrom).AxisY
                        intHead = Locat(.iFrom).AxisH
                        MoveCoor(Locat(.iFrom).AxisX, _
                                    Locat(.iFrom).AxisY, _
                                    Locat(.iFrom).AxisH, _
                                    INI_Settings.sngStaticSep * 2)
                    End If


                    intStart = InStr(.Unit, "-")
                    intStart = intStart + 1
                    strUnit = Trim(Mid(.Unit, intStart))
                    If InStr(strUnit, "SU-") > 0 Then strUnit = Replace(strUnit, "SU-", "SU")
                    strUnit = "vehicles.artillery.Artillery$" & strUnit
                    intDir = -1
                    intRnd = Int(Rnd() * 60)
                    MoveCoor(dbX, _
                            dbY, _
                            intHead + (90 * intDir), _
                            intRnd)
                    For intUnit = 1 To .Size
                        MoveCoor(dbX, _
                                dbY, _
                                intHead + (90 * intDir), _
                                INI_Settings.sngStaticSep)
                        strOutput = "  " & .Ident & Format(intUnit - 1, "0") & _
                                    " " & strUnit & _
                                    " " & Format(.Side, "0") & _
                                    " " & Format(dbX, "########.00") & _
                                    " " & Format(dbY, "########.00") & _
                                    " " & Format(intHead + 90, "##0.0")
                        If InStr(strOutput, ".artillery") > 0 Then
                            strOutput = strOutput & _
                                    Format(INI_Settings.sngTankDly, " 0.0") & " " & _
                                    Format(INI_Settings.sngTankRng, "0")
                        Else
                            strOutput = strOutput & " 0.0"
                        End If

                        ReDim Preserve Chief(Chief.Length)
                        Chief(Chief.Length - 1) = strOutput
                    Next
                End If
            Else
                For intRd = Trail.Length - 1 To 1 Step -1
                    If (Trail(intRd).iFrom = .iTo And _
                            Trail(intRd).iTo = .iFrom) Or _
                            (Trail(intRd).iFrom = .iFrom And _
                            Trail(intRd).iTo = .iTo) Then
                        If .Side = 1 Then
                            dbX = Trail(intRd).AlliedX
                            dbY = Trail(intRd).AlliedY
                            intHead = Trail(intRd).AlliedH
                        Else
                            dbX = Trail(intRd).AxisX
                            dbY = Trail(intRd).AxisY
                            intHead = Trail(intRd).AxisH
                        End If
                        Exit For
                    End If
                Next
                If intRd > 1 Then
                    If (Locat(.iFrom).Moving) And _
                              (Trail(intRd).iEnd - Trail(intRd).Start > 2 * (INI_Settings.ColSpawn + 3)) And _
                              ((Trail(intRd).iFrom = .iFrom And Trail(intRd).AxisSP <= INI_Settings.ColSpawn) Or _
                              (Trail(intRd).iTo = .iFrom And Trail(intRd).AlliedSP < INI_Settings.ColSpawn)) Then
                        PlaceInfantryMoving(intChief, _
                                            intRd, _
                                            MissSettings, _
                                            Infantry, _
                                            Trail, _
                                            ChiefMov, _
                                            ChiefRd, _
                                            TrailWP, _
                                            INI_Settings)
                    Else
                        If .Side = 1 Then
                            MoveCoor(Trail(intRd).AlliedX, _
                                Trail(intRd).AlliedY, _
                                Trail(intRd).AlliedH, _
                                INI_Settings.sngStaticSep * 2)
                        Else
                            MoveCoor(Trail(intRd).AxisX, _
                                Trail(intRd).AxisY, _
                                Trail(intRd).AxisH, _
                                INI_Settings.sngStaticSep * 2)
                        End If
                        intStart = InStr(.Unit, "-")
                        intStart = intStart + 1
                        strUnit = Trim(Mid(.Unit, intStart))
                        If InStr(strUnit, "SU-") > 0 Then strUnit = Replace(strUnit, "SU-", "SU")
                        strUnit = "vehicles.artillery.Artillery$" & strUnit
                        intDir = 1
                        intRnd = Int(Rnd() * 60)
                        MoveCoor(dbX, _
                            dbY, _
                            intHead + (90 * intDir), _
                            intRnd)
                        For intUnit = 1 To .Size
                            MoveCoor(dbX, _
                                dbY, _
                                intHead + (90 * intDir), _
                                INI_Settings.sngStaticSep)
                            strOutput = "  " & .Ident & Format(intUnit - 1, "0") & _
                                " " & strUnit & _
                                " " & Format(.Side, "0") & _
                                " " & Format(dbX, "########.00") & _
                                " " & Format(dbY, "########.00") & _
                                " " & Format(intHead + 90, "##0.0")
                            If InStr(strOutput, ".artillery") > 0 Then
                                strOutput = strOutput & _
                                    Format(INI_Settings.sngTankDly, " 0.0") & " " & _
                                    Format(INI_Settings.sngTankRng, "0")
                            Else
                                strOutput = strOutput & " 0.0"
                            End If

                            ReDim Preserve Chief(Chief.Length)
                            Chief(Chief.Length - 1) = strOutput
                        Next
                    End If
                End If
            End If
        End With
    End Sub
    Public Sub PlaceInfantryMoving(ByRef iChief As Integer, _
                                    ByRef iRd As Integer, _
                                    ByRef MissSettings As Mission, _
                                    ByRef Infantry() As Column, _
                                    ByRef Trail() As Waypoint, _
                                    ByRef ChiefMov() As String, _
                                    ByRef ChiefRd() As String, _
                                    ByRef TrailWP() As String, _
                                    ByRef INI_Settings As INI_Class)
        Dim i As Integer
        With Infantry(iChief)
            'Add Moving Chief

            ReDim Preserve ChiefMov(ChiefMov.Length)
            ChiefMov(ChiefMov.Length - 1) = "  " & .Ident & " " & .Unit & " " & Format(.Side, "0")
            'Add trail Name

            ReDim Preserve ChiefRd(ChiefRd.Length)
            ChiefRd(ChiefRd.Length - 1) = "[" & .Ident & "_Road]"
            'Find trail Direction
            If .iFrom = Trail(iRd).iFrom Then
                'First WP
                Trail(iRd).FrmSpn = Trail(iRd).Start + INI_Settings.ColSpawn + 3 - Trail(iRd).AxisSP
                Trail(iRd).FrmStp = Trail(iRd).iEnd - 3 - Trail(iRd).AxisSP

                ReDim Preserve ChiefRd(ChiefRd.Length)
                ChiefRd(ChiefRd.Length - 1) = "  " & TrailWP(Trail(iRd).FrmSpn) & _
                                    Format(INI_Settings.ColDelay * Trail(iRd).AxisSP, " 0") & _
                                    " 2 2.00"
                'Rest of WP's
                For i = Trail(iRd).FrmSpn + 1 To Trail(iRd).FrmStp - 1 Step 1

                    ReDim Preserve ChiefRd(ChiefRd.Length)
                    ChiefRd(ChiefRd.Length - 1) = "  " & TrailWP(i) & " 0 2 2.00"
                Next

                ReDim Preserve ChiefRd(ChiefRd.Length)
                ChiefRd(ChiefRd.Length - 1) = "  " & TrailWP(Trail(iRd).FrmStp)
                Trail(iRd).AxisSP = Trail(iRd).AxisSP + 1
            Else
                'First WP
                Trail(iRd).ToSpn = Trail(iRd).iEnd - INI_Settings.ColSpawn - 3 + Trail(iRd).AlliedSP
                Trail(iRd).ToStp = Trail(iRd).Start + 3 + Trail(iRd).AlliedSP

                ReDim Preserve ChiefRd(ChiefRd.Length)
                'Rest of WP's
                ChiefRd(ChiefRd.Length - 1) = "  " & TrailWP(Trail(iRd).ToSpn) & _
                                    Format(INI_Settings.ColDelay * Trail(iRd).AlliedSP, " 0") & _
                                    " 2 2.00"
                For i = Trail(iRd).ToSpn - 1 To Trail(iRd).ToStp + 1 Step -1

                    ReDim Preserve ChiefRd(ChiefRd.Length)
                    ChiefRd(ChiefRd.Length - 1) = "  " & TrailWP(i) & " 0 2 2.00"
                Next

                ReDim Preserve ChiefRd(ChiefRd.Length)
                ChiefRd(ChiefRd.Length - 1) = "  " & TrailWP(Trail(iRd).ToStp)
                Trail(iRd).AlliedSP = Trail(iRd).AlliedSP + 1
            End If
        End With
    End Sub
    Public Sub FindLocations(ByRef CurrRoute() As Waypoint, _
                                ByRef intRoute As Integer, _
                                ByRef ifrom As Integer, _
                                ByRef ito As Integer, _
                                ByRef Locat() As Location, _
                                ByRef Road() As Waypoint, _
                                ByVal ini_settings As INI_Class)
        Dim intRoadLoc As Integer
        Dim dLength As Double
        Dim dX As Double
        Dim dY As Double
        Locat(ifrom).X = CurrRoute(1).AlliedX
        Locat(ifrom).Y = CurrRoute(1).AlliedY
        Locat(ito).X = CurrRoute(intRoute).AlliedX
        Locat(ito).Y = CurrRoute(intRoute).AlliedY
        'Axis From location for columns
        If Locat(ifrom).AxisX = 0 Then
            Locat(ifrom).AxisX = CurrRoute(1).AlliedX
            Locat(ifrom).AxisY = CurrRoute(1).AlliedY
            FindHead(CurrRoute(2).AlliedX, _
                    CurrRoute(2).AlliedY, _
                    CurrRoute(1).AlliedX, _
                    CurrRoute(1).AlliedY, _
                Locat(ifrom).AxisH)
        End If
        'Axis To location for columns
        If Locat(ito).AxisX = 0 Then
            Locat(ito).AxisX = CurrRoute(intRoute - 1).AlliedX
            Locat(ito).AxisY = CurrRoute(intRoute - 1).AlliedY
            FindHead(CurrRoute(intRoute).AlliedX, _
                CurrRoute(intRoute).AlliedY, _
                CurrRoute(intRoute - 3).AlliedX, _
                CurrRoute(intRoute - 3).AlliedY, _
                Locat(ito).AxisH)
        End If
        'Allied From location for columns

        Locat(ifrom).AlliedX = CurrRoute(2).AlliedX
        Locat(ifrom).AlliedY = CurrRoute(2).AlliedY
        FindHead(CurrRoute(1).AlliedX, _
            CurrRoute(1).AlliedY, _
            CurrRoute(3).AlliedX, _
            CurrRoute(3).AlliedY, _
            Locat(ifrom).AlliedH)

        'Allied To location for columns

        Locat(ito).AlliedX = CurrRoute(intRoute - 1).AlliedX
        Locat(ito).AlliedY = CurrRoute(intRoute - 1).AlliedY
        FindHead(CurrRoute(intRoute - 1).AlliedX, _
            CurrRoute(intRoute - 1).AlliedY, _
            CurrRoute(intRoute).AlliedX, _
            CurrRoute(intRoute).AlliedY, _
            Locat(ito).AlliedH)

        'Add Randomness to Road Locations
        If intRoute < 21 Then
            intRoadLoc = intRoute \ 2
        Else
            intRoadLoc = intRoute - 19
            intRoadLoc = Int(Rnd() * intRoadLoc)
            intRoadLoc = intRoadLoc + 10
        End If
        'Axis Road location for columns
        FindHead(CurrRoute(intRoadLoc).AlliedX, _
                CurrRoute(intRoadLoc).AlliedY, _
                CurrRoute(intRoadLoc - 1).AlliedX, _
                CurrRoute(intRoadLoc - 1).AlliedY, _
                Road(Road.Length - 1).AxisH)
        dX = CurrRoute(intRoadLoc).AlliedX - CurrRoute(intRoadLoc - 1).AlliedX
        dY = CurrRoute(intRoadLoc).AlliedX - CurrRoute(intRoadLoc - 1).AlliedY
        dLength = Math.Sqrt((dX ^ 2) + (dY ^ 2))
        dX = dX * (ini_settings.sngStaticSep * 10) / dLength
        dY = dY * (ini_settings.sngStaticSep * 10) / dLength
        Road(Road.Length - 1).AxisX = CurrRoute(intRoadLoc).AlliedX + dX
        Road(Road.Length - 1).AxisY = CurrRoute(intRoadLoc).AlliedY + dY
        'Allied Road location for columns
        FindHead(CurrRoute(intRoadLoc).AlliedX, _
                CurrRoute(intRoadLoc).AlliedY, _
                CurrRoute(intRoadLoc + 1).AlliedX, _
                CurrRoute(intRoadLoc + 1).AlliedY, _
                Road(Road.Length - 1).AlliedH)
        dX = CurrRoute(intRoadLoc + 1).AlliedX - CurrRoute(intRoadLoc).AlliedX
        dY = CurrRoute(intRoadLoc + 1).AlliedY - CurrRoute(intRoadLoc).AlliedY
        dLength = Math.Sqrt((dX ^ 2) + (dY ^ 2))
        dX = dX * (ini_settings.sngStaticSep * 10) / dLength
        dY = dY * (ini_settings.sngStaticSep * 10) / dLength
        Road(Road.Length - 1).AlliedX = CurrRoute(intRoadLoc).AlliedX + dX
        Road(Road.Length - 1).AlliedY = CurrRoute(intRoadLoc).AlliedY + dY
    End Sub
    Public Sub FindStations(ByRef CurrRoute() As Waypoint, _
                            ByRef intRoute As Integer, _
                            ByRef iFrom As Integer, _
                            ByRef ito As Integer, _
                            ByRef Station() As Location, _
                            ByRef Rail() As Waypoint)
        Dim intRoadLoc As Integer
        Station(iFrom).X = CurrRoute(1).AlliedX
        Station(iFrom).Y = CurrRoute(1).AlliedY
        Station(ito).X = CurrRoute(intRoute).AlliedX
        Station(ito).Y = CurrRoute(intRoute).AlliedY
        'Axis From stationion for columns
        Station(iFrom).AxisX = CurrRoute(2).AlliedX
        Station(iFrom).AxisY = CurrRoute(2).AlliedY
        FindHead(CurrRoute(2).AlliedX, _
                CurrRoute(2).AlliedY, _
                CurrRoute(1).AlliedX, _
                CurrRoute(1).AlliedY, _
                Station(iFrom).AxisH)
        'Axis To stationion for columns
        Station(ito).AxisX = CurrRoute(intRoute - 2).AlliedX
        Station(ito).AxisY = CurrRoute(intRoute - 2).AlliedY
        FindHead(CurrRoute(intRoute - 3).AlliedX, _
                CurrRoute(intRoute - 3).AlliedY, _
                CurrRoute(intRoute - 4).AlliedX, _
                CurrRoute(intRoute - 4).AlliedY, _
                Station(ito).AxisH)
        'Allied From stationion for columns
        Station(iFrom).AlliedX = CurrRoute(3).AlliedX
        Station(iFrom).AlliedY = CurrRoute(3).AlliedY
        FindHead(CurrRoute(3).AlliedX, _
                CurrRoute(3).AlliedY, _
                CurrRoute(4).AlliedX, _
                CurrRoute(4).AlliedY, _
                Station(iFrom).AlliedH)

        'Allied To stationion for columns
        Station(ito).AlliedX = CurrRoute(intRoute - 1).AlliedX
        Station(ito).AlliedY = CurrRoute(intRoute - 1).AlliedY
        FindHead(CurrRoute(intRoute - 1).AlliedX, _
                CurrRoute(intRoute - 1).AlliedY, _
                CurrRoute(intRoute).AlliedX, _
                CurrRoute(intRoute).AlliedY, _
                Station(ito).AlliedH)
        'Add Randomness to Road Locations
        If intRoute < 21 Then
            intRoadLoc = intRoute \ 2
        Else
            intRoadLoc = intRoute - 19
            intRoadLoc = Int(Rnd() * intRoadLoc)
            intRoadLoc = intRoadLoc + 10
        End If
        'Axis Rail Location for trains
        Rail(Rail.Length - 1).AxisX = CurrRoute(intRoadLoc - 1).AlliedX
        Rail(Rail.Length - 1).AxisY = CurrRoute(intRoadLoc - 1).AlliedY
        FindHead(CurrRoute(intRoadLoc - 1).AlliedX, _
                CurrRoute(intRoadLoc - 1).AlliedY, _
                CurrRoute(intRoadLoc - 2).AlliedX, _
                CurrRoute(intRoadLoc - 2).AlliedY, _
                Rail(Rail.Length - 1).AxisH)

        'Allied Rail Location for trains
        Rail(Rail.Length - 1).AlliedX = CurrRoute(intRoadLoc + 1).AlliedX
        Rail(Rail.Length - 1).AlliedY = CurrRoute(intRoadLoc + 1).AlliedY
        FindHead(CurrRoute(intRoadLoc + 1).AlliedX, _
                CurrRoute(intRoadLoc + 1).AlliedY, _
                CurrRoute(intRoadLoc + 2).AlliedX, _
                CurrRoute(intRoadLoc + 2).AlliedY, _
                Rail(Rail.Length - 1).AlliedH)

    End Sub
    Public Sub FindHarbors(ByRef CurrRoute() As Waypoint, _
                            ByRef intRoute As Integer, _
                            ByRef iFrom As Integer, _
                            ByRef iTo As Integer, _
                            ByRef Harbor() As Location, _
                            ByRef ShipRoute() As Waypoint, _
                            ByRef INI_Settings As INI_Class)
        Dim intRoadLoc As Integer
        Harbor(iFrom).X = CurrRoute(1).AlliedX
        Harbor(iFrom).Y = CurrRoute(1).AlliedY
        Harbor(iTo).X = CurrRoute(intRoute).AlliedX
        Harbor(iTo).Y = CurrRoute(intRoute).AlliedY
        'Axis From harbor for columns
        Harbor(iFrom).AxisX = CurrRoute(2).AlliedX
        Harbor(iFrom).AxisY = CurrRoute(2).AlliedY
        FindHead(CurrRoute(2).AlliedX, _
                CurrRoute(2).AlliedY, _
                CurrRoute(1).AlliedX, _
                CurrRoute(1).AlliedY, _
                Harbor(iFrom).AxisH)
        'Axis To harbor for columns
        Harbor(iTo).AxisX = CurrRoute(intRoute - 2).AlliedX
        Harbor(iTo).AxisY = CurrRoute(intRoute - 2).AlliedY
        FindHead(CurrRoute(intRoute - 3).AlliedX, _
                CurrRoute(intRoute - 3).AlliedY, _
                CurrRoute(intRoute - 4).AlliedX, _
                CurrRoute(intRoute - 4).AlliedY, _
                Harbor(iTo).AxisH)
        'Allied From harbor for columns
        Harbor(iFrom).AlliedX = CurrRoute(3).AlliedX
        Harbor(iFrom).AlliedY = CurrRoute(3).AlliedY
        FindHead(CurrRoute(3).AlliedX, _
                CurrRoute(3).AlliedY, _
                CurrRoute(4).AlliedX, _
                CurrRoute(4).AlliedY, _
                Harbor(iFrom).AlliedH)
        'Allied To harbor for columns
        Harbor(iTo).AlliedX = CurrRoute(intRoute - 1).AlliedX
        Harbor(iTo).AlliedY = CurrRoute(intRoute - 1).AlliedY
        FindHead(CurrRoute(intRoute - 1).AlliedX, _
                CurrRoute(intRoute - 1).AlliedY, _
                CurrRoute(intRoute).AlliedX, _
                CurrRoute(intRoute).AlliedY, _
                Harbor(iTo).AlliedH)
        If INI_Settings.iMovingDF < 1 Then
            'Add Randomness to Road Locations
            If intRoute < 21 Then
                intRoadLoc = intRoute \ 2
            Else
                intRoadLoc = intRoute - 19
                intRoadLoc = Int(Rnd() * intRoadLoc)
                intRoadLoc = intRoadLoc + 10
            End If
            'Axis Shipping Location for Ships
            ShipRoute(ShipRoute.Length - 1).AxisX = CurrRoute(intRoadLoc - 1).AlliedX
            ShipRoute(ShipRoute.Length - 1).AxisY = CurrRoute(intRoadLoc - 1).AlliedY
            FindHead(CurrRoute(intRoadLoc - 1).AlliedX, _
                CurrRoute(intRoadLoc - 1).AlliedY, _
                CurrRoute(intRoadLoc - 2).AlliedX, _
                CurrRoute(intRoadLoc - 2).AlliedY, _
                ShipRoute(ShipRoute.Length - 1).AxisH)
            MoveShipCoor(ShipRoute(ShipRoute.Length - 1).AxisX, _
                    ShipRoute(ShipRoute.Length - 1).AxisY, _
                    ShipRoute(ShipRoute.Length - 1).AxisH, _
                    2000)

            'Allied Shipping Location for ships
            ShipRoute(ShipRoute.Length - 1).AlliedX = CurrRoute(intRoadLoc + 1).AlliedX
            ShipRoute(ShipRoute.Length - 1).AlliedY = CurrRoute(intRoadLoc + 1).AlliedY
            FindHead(CurrRoute(intRoadLoc + 1).AlliedX, _
                CurrRoute(intRoadLoc + 1).AlliedY, _
                CurrRoute(intRoadLoc + 2).AlliedX, _
                CurrRoute(intRoadLoc + 2).AlliedY, _
                ShipRoute(ShipRoute.Length - 1).AlliedH)
            MoveShipCoor(ShipRoute(ShipRoute.Length - 1).AlliedX, _
                    ShipRoute(ShipRoute.Length - 1).AlliedY, _
                    ShipRoute(ShipRoute.Length - 1).AlliedH, _
                    2000)
        Else
            'Axis Shipping
            ShipRoute(ShipRoute.Length - 1).AxisX = 0
            ShipRoute(ShipRoute.Length - 1).AxisY = 0
            FindHead(CurrRoute(2).AlliedX, _
                CurrRoute(2).AlliedY, _
                CurrRoute(1).AlliedX, _
                CurrRoute(1).AlliedY, _
                ShipRoute(ShipRoute.Length - 1).AxisH)
            'Allied Shipping
            ShipRoute(ShipRoute.Length - 1).AlliedX = 0
            ShipRoute(ShipRoute.Length - 1).AlliedY = 0
            FindHead(CurrRoute(intRoute - 1).AlliedX, _
                CurrRoute(intRoute - 1).AlliedY, _
                CurrRoute(intRoute).AlliedX, _
                CurrRoute(intRoute).AlliedY, _
                ShipRoute(ShipRoute.Length - 1).AlliedH)
        End If
    End Sub
    Public Sub FindTrailLocations(ByRef CurrRoute() As Waypoint, _
                            ByRef intRoute As Integer, _
                            ByRef iFrom As Integer, _
                            ByRef iTo As Integer, _
                            ByRef Locat() As Location, _
                            ByRef Trail() As Waypoint)
        Dim intTrailLoc As Integer
        Locat(iFrom).X = CurrRoute(1).AlliedX
        Locat(iFrom).Y = CurrRoute(1).AlliedY
        Locat(iTo).X = CurrRoute(intRoute).AlliedX
        Locat(iTo).Y = CurrRoute(intRoute).AlliedY
        'Axis From location for columns
        If Locat(iFrom).AxisX = 0 Then
            Locat(iFrom).AxisX = CurrRoute(2).AlliedX
            Locat(iFrom).AxisY = CurrRoute(2).AlliedY
            FindHead(CurrRoute(2).AlliedX, _
                    CurrRoute(2).AlliedY, _
                    CurrRoute(1).AlliedX, _
                    CurrRoute(1).AlliedY, _
                Locat(iFrom).AxisH)
        End If
        'Axis To location for columns
        If Locat(iTo).AxisX = 0 Then
            Locat(iTo).AxisX = CurrRoute(intRoute - 3).AlliedX
            Locat(iTo).AxisY = CurrRoute(intRoute - 3).AlliedY
            FindHead(CurrRoute(intRoute).AlliedX, _
                CurrRoute(intRoute).AlliedY, _
                CurrRoute(intRoute - 3).AlliedX, _
                CurrRoute(intRoute - 3).AlliedY, _
                Locat(iTo).AxisH)
        End If
        'Allied From location for columns

        Locat(iFrom).AlliedX = CurrRoute(3).AlliedX
        Locat(iFrom).AlliedY = CurrRoute(3).AlliedY
        FindHead(CurrRoute(1).AlliedX, _
            CurrRoute(1).AlliedY, _
            CurrRoute(3).AlliedX, _
            CurrRoute(3).AlliedY, _
            Locat(iFrom).AlliedH)

        'Allied To location for columns

        Locat(iTo).AlliedX = CurrRoute(intRoute - 1).AlliedX
        Locat(iTo).AlliedY = CurrRoute(intRoute - 1).AlliedY
        FindHead(CurrRoute(intRoute - 1).AlliedX, _
            CurrRoute(intRoute - 1).AlliedY, _
            CurrRoute(intRoute).AlliedX, _
            CurrRoute(intRoute).AlliedY, _
            Locat(iTo).AlliedH)

        'Add Randomness to trail Locations
        If intRoute < 21 Then
            intTrailLoc = intRoute \ 2
        Else
            intTrailLoc = intRoute - 19
            intTrailLoc = Int(Rnd() * intTrailLoc)
            intTrailLoc = intTrailLoc + 10
        End If
        'Axis trail location for columns
        Trail(Trail.Length - 1).AxisX = CurrRoute(intTrailLoc - 1).AlliedX
        Trail(Trail.Length - 1).AxisY = CurrRoute(intTrailLoc - 1).AlliedY
        FindHead(CurrRoute(intTrailLoc - 1).AlliedX, _
                CurrRoute(intTrailLoc - 1).AlliedY, _
                CurrRoute(intTrailLoc - 2).AlliedX, _
                CurrRoute(intTrailLoc - 2).AlliedY, _
                Trail(Trail.Length - 1).AxisH)

        'Allied trail location for columns
        Trail(Trail.Length - 1).AlliedX = CurrRoute(intTrailLoc + 1).AlliedX
        Trail(Trail.Length - 1).AlliedY = CurrRoute(intTrailLoc + 1).AlliedY
        FindHead(CurrRoute(intTrailLoc + 1).AlliedX, _
                    CurrRoute(intTrailLoc + 1).AlliedY, _
                    CurrRoute(intTrailLoc + 2).AlliedX, _
                    CurrRoute(intTrailLoc + 2).AlliedY, _
                    Trail(Trail.Length - 1).AlliedH)
        Return

    End Sub

    Public Sub butGenerate_Click(ByVal sender As Object, ByVal e As System.EventArgs, _
                                ByRef INI_Settings As INI_Class)
        Dim strError As String = "Campaign Updated and Mission Generated Successfully"
        Dim strCommand As String = "-nomis"
        Main(strCommand, _
             strError, _
             INI_Settings)
        'lbResult.Text = strError
    End Sub

    Public Sub butUpdate_Click(ByVal sender As Object, ByVal e As System.EventArgs, _
                                ByRef INI_Settings As INI_Class)
        Dim strError As String = "Campaign Updated Successfully"
        Dim strCommand As String = ""
        Main(strCommand, _
             strError, _
             INI_Settings)
        'lbResult.Text = strError
    End Sub

    Public Sub Find_Route_Folder(ByRef bolError As Boolean, _
                                 ByRef sError As String, _
                                 ByRef sFolder As String, _
                                 ByRef sRoute As String)
        Dim i As Integer
        If Len(sFolder) < 4 Then
            bolError = True
            sError = "Cannot find route folder from campaign folder!"
            Exit Sub
        End If
        If Mid(sFolder, Len(sFolder), 1) = "\" Then sFolder = Left(sFolder, Len(sFolder) - 1)
        For i = Len(sFolder) To 4 Step -1
            If Mid(sFolder, i, 1) = "\" Then
                sRoute = Left(sFolder, i - 1)
                Exit For
            End If
        Next
        If i < 4 Then
            bolError = True
            sError = "Cannot find route folder from campaign folder!"
            Exit Sub
        End If
    End Sub
    Public Sub Check_Supply_Base(ByRef BornPlace() As BornPlaceClass, _
                                 ByRef Camp_Settings As Campaign, _
                                 ByRef Squads() As Squad_Type, _
                                 ByRef AC_New() As AC_Type, _
                                 ByRef Locat() As Location, _
                                 ByRef Weapons() As Weap)
        Dim iSide As Integer
        Dim dDistance As Double
        Dim dTemp As Double
        Dim iBP As Integer
        Dim iNewBP As Integer
        Dim iCloseBP As Integer
        Dim iSquad As Integer
        Dim iAC As Integer
        Dim iWeap As Integer
        For iSide = 1 To 2
            dDistance = 1000000
            If iSide = 1 Then
                For iBP = BornPlace.Length - 1 To 1 Step -1
                    If Camp_Settings.RuHome = BornPlace(iBP).Loc Then Exit For
                Next
                If BornPlace(iBP).Side <> iSide Then
                    For iNewBP = 1 To BornPlace.Length - 1
                        dTemp = Math.Sqrt(((BornPlace(iBP).X - BornPlace(iNewBP).X) ^ 2) + ((BornPlace(iBP).Y - BornPlace(iNewBP).Y) ^ 2))
                        If dTemp < dDistance And _
                                BornPlace(iNewBP).Side = iSide And _
                                BornPlace(iNewBP).Type = 0 Then
                            iCloseBP = iNewBP
                            dDistance = dTemp
                        End If
                    Next
                    With BornPlace(iCloseBP)
                        Camp_Settings.RuHome = .Loc
                        For iAC = 1 To AC_New.Length - 1
                            If AC_New(iAC).Side = iSide And AC_New(iAC).Type = 0 Then
                                For iSquad = Squads.Length - 1 To 1 Step -1
                                    If AC_New(iAC).Coop = Squads(iSquad).Coop And _
                                            BornPlace(iCloseBP).intLoc = Squads(iSquad).iLoc Then
                                        If Squads(iAC).Max > AC_New(iAC).Max Then Squads(iAC).Max = AC_New(iAC).Max
                                        If Squads(iAC).Min < AC_New(iAC).Min Then Squads(iAC).Min = AC_New(iAC).Min
                                        If Squads(iAC).Number > AC_New(iAC).Max Then Squads(iAC).Number = AC_New(iAC).Max
                                        If Squads(iAC).Number < AC_New(iAC).Min Then Squads(iAC).Number = AC_New(iAC).Min
                                        Exit For
                                    End If
                                Next
                                If iSquad < 1 Then
                                    ReDim Preserve Squads(Squads.Length)
                                    With Squads(Squads.Length - 1)
                                        .Coop = AC_New(iAC).Coop
                                        .DF = AC_New(iAC).DF
                                        .FuelLimit = Locat(BornPlace(iCloseBP).intLoc).FuelLimit
                                        .iLoc = BornPlace(iCloseBP).intLoc
                                        .Loc = BornPlace(iCloseBP).Loc
                                        .Max = AC_New(iAC).Max
                                        .Min = AC_New(iAC).Min
                                        .Number = AC_New(iAC).Min
                                        .Side = AC_New(iAC).Side
                                        .Squad = ""
                                        .Suppressed = Locat(BornPlace(iCloseBP).intLoc).Suppressed
                                        .Type = AC_New(iAC).Type
                                        For iWeap = 1 To Weapons.Length - 1
                                            If .Coop = Weapons(iWeap).AC Or .DF = Weapons(iWeap).AC Then
                                                .Weapon = Weapons(iWeap).Weapon
                                            End If
                                        Next
                                    End With
                                End If
                            End If
                        Next
                    End With
                End If
                'Red Seapane Base
                If Camp_Settings.RuSeaHome <> "" Then
                    dDistance = 1000000
                    For iBP = BornPlace.Length - 1 To 1 Step -1
                        If Camp_Settings.RuSeaHome = BornPlace(iBP).Loc Then Exit For
                    Next
                    If BornPlace(iBP).Side <> iSide Then
                        For iNewBP = 1 To BornPlace.Length - 1
                            dTemp = Math.Sqrt(((BornPlace(iBP).X - BornPlace(iNewBP).X) ^ 2) + ((BornPlace(iBP).Y - BornPlace(iNewBP).Y) ^ 2))
                            If dTemp < dDistance And _
                                    BornPlace(iNewBP).Side = iSide And _
                                    BornPlace(iNewBP).Type = 2 Then
                                iCloseBP = iNewBP
                                dDistance = dTemp
                            End If
                        Next
                        With BornPlace(iCloseBP)
                            Camp_Settings.RuSeaHome = .Loc
                            For iAC = 1 To AC_New.Length - 1
                                If AC_New(iAC).Side = iSide And AC_New(iAC).Type = 2 Then
                                    For iSquad = Squads.Length - 1 To 1 Step -1
                                        If AC_New(iAC).Coop = Squads(iSquad).Coop And _
                                                BornPlace(iCloseBP).intLoc = Squads(iSquad).iLoc Then
                                            If Squads(iAC).Max > AC_New(iAC).Max Then Squads(iAC).Max = AC_New(iAC).Max
                                            If Squads(iAC).Min < AC_New(iAC).Min Then Squads(iAC).Min = AC_New(iAC).Min
                                            If Squads(iAC).Number > AC_New(iAC).Max Then Squads(iAC).Number = AC_New(iAC).Max
                                            If Squads(iAC).Number < AC_New(iAC).Min Then Squads(iAC).Number = AC_New(iAC).Min
                                            Exit For
                                        End If
                                    Next
                                    If iSquad < 1 Then
                                        ReDim Preserve Squads(Squads.Length)
                                        With Squads(Squads.Length - 1)
                                            .Coop = AC_New(iAC).Coop
                                            .DF = AC_New(iAC).DF
                                            .iLoc = BornPlace(iCloseBP).intLoc
                                            .Loc = BornPlace(iCloseBP).Loc
                                            .Max = AC_New(iAC).Max
                                            .Min = AC_New(iAC).Min
                                            .Number = AC_New(iAC).Min
                                            .Side = AC_New(iAC).Side
                                            .Squad = ""
                                            .Type = AC_New(iAC).Type
                                            If BornPlace(iCloseBP).intLoc > 0 Then
                                                .Suppressed = Locat(BornPlace(iCloseBP).intLoc).Suppressed
                                                .FuelLimit = Locat(BornPlace(iCloseBP).intLoc).FuelLimit
                                            Else
                                                .Suppressed = 0
                                                .FuelLimit = 100
                                            End If
                                            For iWeap = 1 To Weapons.Length - 1
                                                If .Coop = Weapons(iWeap).AC Or .DF = Weapons(iWeap).AC Then
                                                    .Weapon = Weapons(iWeap).Weapon
                                                End If
                                            Next
                                        End With
                                    End If
                                End If
                            Next
                        End With
                    End If
                End If

            Else
                'Blue Home Base
                For iBP = BornPlace.Length - 1 To 1 Step -1
                    If Camp_Settings.DeHome = BornPlace(iBP).Loc Then Exit For
                Next
                If BornPlace(iBP).Side <> iSide Then
                    For iNewBP = 1 To BornPlace.Length - 1
                        dTemp = Math.Sqrt(((BornPlace(iBP).X - BornPlace(iNewBP).X) ^ 2) + ((BornPlace(iBP).Y - BornPlace(iNewBP).Y) ^ 2))
                        If dTemp < dDistance And _
                                BornPlace(iNewBP).Side = iSide And _
                                BornPlace(iNewBP).Type = 0 Then
                            iCloseBP = iNewBP
                            dDistance = dTemp
                        End If
                    Next
                    With BornPlace(iCloseBP)
                        Camp_Settings.RuHome = .Loc
                        For iAC = 1 To AC_New.Length - 1
                            If AC_New(iAC).Side = iSide And AC_New(iAC).Type = 0 Then
                                For iSquad = Squads.Length - 1 To 1 Step -1
                                    If AC_New(iAC).Coop = Squads(iSquad).Coop And _
                                            BornPlace(iCloseBP).intLoc = Squads(iSquad).iLoc Then
                                        If Squads(iAC).Max > AC_New(iAC).Max Then Squads(iAC).Max = AC_New(iAC).Max
                                        If Squads(iAC).Min < AC_New(iAC).Min Then Squads(iAC).Min = AC_New(iAC).Min
                                        If Squads(iAC).Number > AC_New(iAC).Max Then Squads(iAC).Number = AC_New(iAC).Max
                                        If Squads(iAC).Number < AC_New(iAC).Min Then Squads(iAC).Number = AC_New(iAC).Min
                                        Exit For
                                    End If
                                Next
                                If iSquad < 1 Then
                                    ReDim Preserve Squads(Squads.Length)
                                    With Squads(Squads.Length - 1)
                                        .Coop = AC_New(iAC).Coop
                                        .DF = AC_New(iAC).DF
                                        .iLoc = BornPlace(iCloseBP).intLoc
                                        .Loc = BornPlace(iCloseBP).Loc
                                        .Max = AC_New(iAC).Max
                                        .Min = AC_New(iAC).Min
                                        .Number = AC_New(iAC).Min
                                        .Side = AC_New(iAC).Side
                                        .Squad = ""
                                        .Type = AC_New(iAC).Type
                                        If BornPlace(iCloseBP).intLoc > 0 Then
                                            .Suppressed = Locat(BornPlace(iCloseBP).intLoc).Suppressed
                                            .FuelLimit = Locat(BornPlace(iCloseBP).intLoc).FuelLimit
                                        Else
                                            .Suppressed = 0
                                            .FuelLimit = 100
                                        End If
                                        For iWeap = 1 To Weapons.Length - 1
                                            If .Coop = Weapons(iWeap).AC Or .DF = Weapons(iWeap).AC Then
                                                .Weapon = Weapons(iWeap).Weapon
                                            End If
                                        Next
                                    End With
                                End If
                            End If
                        Next
                    End With
                End If
                'Blue Seapane Base
                If Camp_Settings.DeSeaHome <> "" Then
                    dDistance = 1000000
                    For iBP = BornPlace.Length - 1 To 1 Step -1
                        If Camp_Settings.RuSeaHome = BornPlace(iBP).Loc Then Exit For
                    Next
                    If BornPlace(iBP).Side <> iSide Then
                        For iNewBP = 1 To BornPlace.Length - 1
                            dTemp = Math.Sqrt(((BornPlace(iBP).X - BornPlace(iNewBP).X) ^ 2) + ((BornPlace(iBP).Y - BornPlace(iNewBP).Y) ^ 2))
                            If dTemp < dDistance And _
                                    BornPlace(iNewBP).Side = iSide And _
                                    BornPlace(iNewBP).Type = 2 Then
                                iCloseBP = iNewBP
                                dDistance = dTemp
                            End If
                        Next
                        With BornPlace(iCloseBP)
                            Camp_Settings.DeSeaHome = .Loc
                            For iAC = 1 To AC_New.Length - 1
                                If AC_New(iAC).Side = iSide And AC_New(iAC).Type = 2 Then
                                    For iSquad = Squads.Length - 1 To 1 Step -1
                                        If AC_New(iAC).Coop = Squads(iSquad).Coop And _
                                                BornPlace(iCloseBP).intLoc = Squads(iSquad).iLoc Then
                                            If Squads(iAC).Max > AC_New(iAC).Max Then Squads(iAC).Max = AC_New(iAC).Max
                                            If Squads(iAC).Min < AC_New(iAC).Min Then Squads(iAC).Min = AC_New(iAC).Min
                                            If Squads(iAC).Number > AC_New(iAC).Max Then Squads(iAC).Number = AC_New(iAC).Max
                                            If Squads(iAC).Number < AC_New(iAC).Min Then Squads(iAC).Number = AC_New(iAC).Min
                                            Exit For
                                        End If
                                    Next
                                    If iSquad < 1 Then
                                        ReDim Preserve Squads(Squads.Length)
                                        With Squads(Squads.Length - 1)
                                            .Coop = AC_New(iAC).Coop
                                            .DF = AC_New(iAC).DF
                                            .FuelLimit = Locat(BornPlace(iCloseBP).intLoc).FuelLimit
                                            .iLoc = BornPlace(iCloseBP).intLoc
                                            .Loc = BornPlace(iCloseBP).Loc
                                            .Max = AC_New(iAC).Max
                                            .Min = AC_New(iAC).Min
                                            .Number = AC_New(iAC).Min
                                            .Side = AC_New(iAC).Side
                                            .Squad = ""
                                            .Suppressed = Locat(BornPlace(iCloseBP).intLoc).Suppressed
                                            .Type = AC_New(iAC).Type
                                            For iWeap = 1 To Weapons.Length - 1
                                                If .Coop = Weapons(iWeap).AC Or .DF = Weapons(iWeap).AC Then
                                                    .Weapon = Weapons(iWeap).Weapon
                                                End If
                                            Next
                                        End With
                                    End If
                                End If
                            Next
                        End With
                    End If
                End If
            End If
        Next
    End Sub
    Public Sub LoadManufactureFile(ByRef ManInfo() As Building, _
                            ByRef ini_settings As INI_Class)
        'Loads info on factory plates from manufacture.dcg file
        Dim sManufactureFile As String
        Dim sInput As String
        Dim sValue As String
        Dim iStart As Integer
        Dim filereader As IO.StreamReader
        sManufactureFile = ini_settings.sData & "manufacture.dcg"
        If Dir(sManufactureFile) = "" Then Exit Sub
        filereader = My.Computer.FileSystem.OpenTextFileReader(sManufactureFile)
        Do Until filereader.EndOfStream
            sInput = filereader.ReadLine
            sInput = sInput.Trim
            If sInput.Contains("[") And sInput.Contains("]") Then
                sValue = sInput.Replace("[", "")
                sValue = sValue.Replace("]", "")
                sValue = sValue.Trim
                ReDim Preserve ManInfo(ManInfo.Length)
                ManInfo(ManInfo.Length - 1).Unit = sValue
            Else
                If ManInfo.Length > 1 Then
                    If sInput.Contains("manufacture=") Then
                        iStart = InStr(sInput, "=")
                        ManInfo(ManInfo.Length - 1).Manufacture = Val(Mid(sInput, iStart + 1))
                    End If
                End If
            End If
        Loop
        filereader.Close()
    End Sub
    Public Sub LoadPlateFile(ByRef Manufacture() As Factory, _
                             ByRef ManInfo() As Building, _
                             ByRef Locat() As Location, _
                             ByRef INI_Settings As INI_Class)

        Dim sPlateFile As String
        Dim i As Integer
        Dim sInput As String
        Dim filereader As IO.StreamReader
        sPlateFile = INI_Settings.sCampaign & "\plates.dcg"
        If My.Computer.FileSystem.FileExists(sPlateFile) Then
            filereader = My.Computer.FileSystem.OpenTextFileReader(sPlateFile)
            Do Until filereader.EndOfStream
                sInput = filereader.ReadLine
                sInput = sInput.Trim
                If sInput.Contains("_plate") Then

                    Dim sArray() As String
                    sArray = sInput.Split("  ")
                            ReDim Preserve Manufacture(Manufacture.Length)
                            With Manufacture(Manufacture.Length - 1)
                                For i = 0 To sArray.Length - 1
                                    If i = 0 Then .ID = sArray(i)
                                    If i = 1 Then .Unit = sArray(i)
                                    If i = 2 Then .Side = Val(sArray(i))
                                    If i = 3 Then .X = Val(sArray(i))
                                    If i = 4 Then .Y = Val(sArray(i))
                                    If i = 5 Then .Head = sArray(i)
                                    If i = 10 Then .Manufacture = Val(sArray(i))
                                    If i > 5 And i < 10 Then
                                        .Other &= " " & sArray(i)
                                        .Other = .Other.Trim
                                    End If
                                Next
                                For i = 1 To ManInfo.Length - 1
                                    If .Unit = ManInfo(i).Unit Then
                                        .Struct = i
                                        .MaxMan = ManInfo(i).Manufacture
                                        If .Manufacture > .MaxMan Then .Manufacture = .MaxMan
                                        If .Manufacture < 0 Then .Manufacture = .MaxMan
                                        Exit For
                                    End If
                                Next
                                FindWayPoint(.X, _
                                                .Y, _
                                                .Loc, _
                                                .intLoc, _
                                                Locat)
                                If .Struct < 1 Or .intLoc < 1 Then
                                    ReDim Preserve Manufacture(Manufacture.Length - 2)
                                End If
                            End With

                End If
            Loop
            filereader.Close()
        End If
    End Sub
    Public Sub GenPlateFile(ByRef Manufacture() As Factory, _
                            ByRef INI_Settings As INI_Class)
        Dim intLine As Integer
        Dim sb As New StringBuilder
        sb.AppendLine("[Plate]")
        For intLine = Manufacture.Length - 1 To 1 Step -1
            With Manufacture(intLine)
                sb.AppendLine("  " & .ID & " " & _
                        .Unit & " " & _
                        Format(.Side, "0") & " " & _
                        Format(.X, "0.00") & " " & _
                        Format(.Y, "0.00") & " " & _
                        Format(.Head, "0.00") & " " & _
                        .Other & " " & _
                        Format(.Manufacture, "0.00"))
            End With
        Next

        Using outfile As New StreamWriter(INI_Settings.sCampaign & "\plates.dcg")
            outfile.Write(sb.ToString())
            outfile.Close()
        End Using
    End Sub
    Private Sub Fix_ColLoc(ByRef ColLoc() As String, _
                            ByVal Location As String, _
                            ByVal ID As String)
        Dim i As Integer
        For i = 1 To ColLoc.Length - 1
            Dim sArray() As String
            sArray = ColLoc(i).Split(" ")
            If sArray(0) = ID Then
                ColLoc(i) = ID & " @" & Location
                Exit For
            End If
        Next
    End Sub
End Module
